Merge "Synchronous Set/Get behaviour for default properties" into devel/master
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-RenderTask.cpp
1 /*
2  * Copyright (c) 2017 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 <iostream>
19 #include <stdlib.h>
20 #include <dali/public-api/dali-core.h>
21 #include <dali/devel-api/events/hit-test-algorithm.h>
22 #include <dali/devel-api/object/handle-devel.h>
23 #include <dali-test-suite-utils.h>
24 #include <dali/integration-api/debug.h>
25 #include <test-native-image.h>
26
27 #include <mesh-builder.h>
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
84 const int RENDER_FRAME_INTERVAL = 16;                           ///< Duration of each frame in ms. (at approx 60FPS)
85
86 /*
87  * Simulate time passed by.
88  *
89  * @note this will always process at least 1 frame (1/60 sec)
90  *
91  * @param application Test application instance
92  * @param duration Time to pass in milliseconds.
93  * @return The actual time passed in milliseconds
94  */
95 int Wait(TestApplication& application, int duration = 0)
96 {
97   int time = 0;
98
99   for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
100   {
101     application.SendNotification();
102     application.Render(RENDER_FRAME_INTERVAL);
103     time += RENDER_FRAME_INTERVAL;
104   }
105
106   return time;
107 }
108
109 struct RenderTaskFinished
110 {
111   RenderTaskFinished( bool& finished )
112   : finished( finished )
113   {
114   }
115
116   void operator()( RenderTask& renderTask )
117   {
118     finished = true;
119   }
120
121   bool& finished;
122 };
123
124 struct RenderTaskFinishedRemoveSource
125 {
126   RenderTaskFinishedRemoveSource( bool& finished )
127   : finished( finished ),
128     finishedOnce(false)
129   {
130   }
131
132   void operator()( RenderTask& renderTask )
133   {
134     DALI_TEST_CHECK(finishedOnce == false);
135     finished = true;
136     finishedOnce = true;
137     Actor srcActor = renderTask.GetSourceActor();
138     UnparentAndReset(srcActor);
139   }
140
141   bool& finished;
142   bool finishedOnce;
143 };
144
145 struct RenderTaskFinishedRenderAgain
146 {
147   RenderTaskFinishedRenderAgain( bool& finished )
148   : finished( finished ),
149     finishedOnce(false)
150   {
151   }
152
153   void operator()( RenderTask& renderTask )
154   {
155     DALI_TEST_CHECK(finishedOnce == false);
156     finished = true;
157     finishedOnce = true;
158     renderTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
159   }
160
161   bool& finished;
162   bool finishedOnce;
163 };
164
165
166 bool TestScreenToFrameBufferFunction( Vector2& coordinates )
167 {
168   coordinates = coordinates + Vector2( 1, 2 );
169
170   return true;
171 }
172
173 Actor CreateRenderableActorSuccess(TestApplication& application, std::string filename)
174 {
175   PrepareResourceImage( application, 80u, 80u, Pixel::RGBA8888 );
176   Image image = ResourceImage::New(filename);
177   Actor actor = CreateRenderableActor(image);
178   actor.SetSize( 80, 80 );
179   return actor;
180 }
181
182 Actor CreateRenderableActorFailed(TestApplication& application, std::string filename)
183 {
184   Image image = ResourceImage::New(filename);
185   DALI_TEST_CHECK( image );
186   Actor actor = CreateRenderableActor(image);
187   actor.SetSize( 80, 80 );
188   return actor;
189 }
190
191 Image CreateResourceImage(TestApplication& application, std::string filename)
192 {
193   PrepareResourceImage( application, 80u, 80u, Pixel::RGBA8888 );
194   Image image = ResourceImage::New(filename);
195   DALI_TEST_CHECK( image );
196   return image;
197 }
198
199 RenderTask CreateRenderTask(TestApplication& application,
200                             CameraActor offscreenCamera,
201                             Actor rootActor,       // Reset default render task to point at this actor
202                             Actor secondRootActor, // Source actor
203                             unsigned int refreshRate,
204                             bool glSync)
205 {
206   // Change main render task to use a different root
207   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
208   taskList.GetTask(0u).SetSourceActor( rootActor );
209
210   FrameBufferImage frameBufferImage;
211   if( glSync )
212   {
213     NativeImageInterfacePtr testNativeImagePtr = TestNativeImage::New(10, 10);
214     frameBufferImage= FrameBufferImage::New( *(testNativeImagePtr.Get()) );
215   }
216   else
217   {
218     frameBufferImage = FrameBufferImage::New( 10, 10 );
219   }
220
221   // Don't draw output framebuffer // '
222
223   RenderTask newTask = taskList.CreateTask();
224   newTask.SetCameraActor( offscreenCamera );
225   newTask.SetSourceActor( secondRootActor );
226   newTask.SetInputEnabled( false );
227   newTask.SetClearColor( Vector4( 0.f, 0.f, 0.f, 0.f ) );
228   newTask.SetClearEnabled( true );
229   newTask.SetExclusive( true );
230   newTask.SetRefreshRate( refreshRate );
231   newTask.SetTargetFrameBuffer( frameBufferImage );
232   newTask.SetProperty( RenderTask::Property::REQUIRES_SYNC, glSync );
233   return newTask;
234 }
235
236 bool UpdateRender(TestApplication& application, TraceCallStack& callStack, bool testDrawn, bool& finishedSig, bool testFinished, bool testKeepUpdating, int lineNumber )
237 {
238   finishedSig = false;
239   callStack.Reset();
240
241   tet_printf("TestApplication::UpdateRender().\n");
242
243   application.Render(16);
244   application.SendNotification();
245
246   bool sigPassed = false;
247   if( testFinished )
248   {
249     sigPassed = finishedSig;
250   }
251   else
252   {
253     sigPassed = ! finishedSig;
254   }
255
256   bool drawResult = callStack.FindMethod("DrawElements") || callStack.FindMethod("DrawArrays");
257
258   bool drawPassed = false;
259   if( testDrawn )
260   {
261     drawPassed = drawResult;
262   }
263   else
264   {
265     drawPassed = !drawResult;
266   }
267
268   bool keepUpdating = (application.GetUpdateStatus() != 0);
269   bool keepUpdatingPassed = false;
270   if( testKeepUpdating )
271   {
272     keepUpdatingPassed = keepUpdating;
273   }
274   else
275   {
276     keepUpdatingPassed = !keepUpdating;
277   }
278
279   bool result = (sigPassed && drawPassed && keepUpdatingPassed);
280
281   tet_printf("UpdateRender: Expected: Draw:%s Signal:%s KeepUpdating: %s  Actual: Draw:%s  Signal:%s KeepUpdating: %s  %s, line %d\n",
282              BOOLSTR(testDrawn), BOOLSTR(testFinished), BOOLSTR(testKeepUpdating),
283              BOOLSTR(drawResult), BOOLSTR(finishedSig), BOOLSTR(keepUpdating),
284              result ? "Passed":"Failed",
285              lineNumber );
286
287   return result;
288 }
289
290 // The functor to be used in the hit-test algorithm to check whether the actor is hittable.
291 bool IsActorHittableFunction(Actor actor, Dali::HitTestAlgorithm::TraverseType type)
292 {
293   bool hittable = false;
294
295   switch (type)
296   {
297     case Dali::HitTestAlgorithm::CHECK_ACTOR:
298     {
299       // Check whether the actor is visible and not fully transparent.
300       if( actor.IsVisible()
301           && actor.GetCurrentWorldColor().a > 0.01f) // not FULLY_TRANSPARENT
302       {
303
304         hittable = true;
305       }
306       break;
307     }
308     case Dali::HitTestAlgorithm::DESCEND_ACTOR_TREE:
309     {
310       if( actor.IsVisible() ) // Actor is visible, if not visible then none of its children are visible.
311       {
312         hittable = true;
313       }
314       break;
315     }
316     default:
317     {
318       break;
319     }
320   }
321
322   return hittable;
323 }
324
325 } // unnamed namespace
326
327
328 /****************************************************************************************************/
329 /****************************************************************************************************/
330 /********************************   TEST CASES BELOW   **********************************************/
331 /****************************************************************************************************/
332 /****************************************************************************************************/
333
334 int UtcDaliRenderTaskDownCast01(void)
335 {
336   TestApplication application;
337
338   tet_infoline("Testing RenderTask::DownCast()");
339
340   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
341
342   BaseHandle base = taskList.GetTask( 0u );
343   DALI_TEST_CHECK( base );
344
345   RenderTask task = RenderTask::DownCast( base );
346   DALI_TEST_CHECK( task );
347
348   // Try calling a method
349   DALI_TEST_CHECK( task.GetSourceActor() );
350   END_TEST;
351 }
352
353 int UtcDaliRenderTaskDownCast02(void)
354 {
355   TestApplication application;
356
357   tet_infoline("Testing RenderTask::DownCast()");
358
359   Actor actor = Actor::New();
360
361   RenderTask task = RenderTask::DownCast( actor );
362   DALI_TEST_CHECK( ! task );
363
364   END_TEST;
365 }
366
367 int UtcDaliRenderTaskSetSourceActorN(void)
368 {
369   TestApplication application;
370   tet_infoline("Testing RenderTask::SetSourceActor() Negative - try with empty actor handle");
371   Stage stage = Stage::GetCurrent();
372
373   Actor srcActor;
374
375   RenderTaskList taskList = stage.GetRenderTaskList();
376   RenderTask renderTask = taskList.CreateTask();
377   renderTask.SetSourceActor(srcActor);
378
379   application.SendNotification();
380   application.Render();
381
382   DALI_TEST_CHECK( ! renderTask.GetSourceActor() );
383   END_TEST;
384 }
385
386
387 int UtcDaliRenderTaskSetSourceActorP01(void)
388 {
389   TestApplication application;
390
391   tet_infoline("Testing RenderTask::SetSourceActor() Positive - check that setting a non-renderable actor stops existing source actor being rendered ");
392
393   Stage stage = Stage::GetCurrent();
394   RenderTaskList taskList = stage.GetRenderTaskList();
395   RenderTask task = taskList.GetTask( 0u );
396
397   Actor actor = task.GetSourceActor();
398   DALI_TEST_CHECK( actor );
399
400   BufferImage img = BufferImage::New( 1,1 );
401   Actor newActor = CreateRenderableActor( img );
402   newActor.SetSize(1,1);
403   stage.Add( newActor );
404
405   Actor nonRenderableActor = Actor::New();
406   stage.Add( nonRenderableActor );
407
408   // Stop the newActor from being rendered by changing the source actor
409   DALI_TEST_CHECK( nonRenderableActor );
410   task.SetSourceActor( nonRenderableActor );
411   DALI_TEST_CHECK( task.GetSourceActor() != actor );
412   DALI_TEST_CHECK( task.GetSourceActor() == nonRenderableActor );
413
414   TestGlAbstraction& gl = application.GetGlAbstraction();
415   TraceCallStack& drawTrace = gl.GetDrawTrace();
416   drawTrace.Enable(true);
417
418   // Update & Render nothing!
419   application.GetGlAbstraction().ClearBoundTextures();
420   application.SendNotification();
421   application.Render();
422
423   // Check that nothing was rendered
424   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 0, TEST_LOCATION );
425
426   END_TEST;
427 }
428
429
430 int UtcDaliRenderTaskSetSourceActorP02(void)
431 {
432   TestApplication application;
433
434   tet_infoline("Testing RenderTask::SetSourceActor() Positive - check that switching source from a non-renderable to a renderable actor causes the texture to be drawn");
435
436   Stage stage = Stage::GetCurrent();
437
438   RenderTaskList taskList = stage.GetRenderTaskList();
439
440   RenderTask task = taskList.GetTask( 0u );
441
442   Actor actor = task.GetSourceActor();
443   DALI_TEST_CHECK( actor );
444
445
446   BufferImage img = BufferImage::New( 1,1 );
447   Actor newActor = CreateRenderableActor( img );
448   newActor.SetSize(1,1);
449   stage.Add( newActor );
450
451   Actor nonRenderableActor = Actor::New();
452   stage.Add( nonRenderableActor );
453
454   TestGlAbstraction& gl = application.GetGlAbstraction();
455   TraceCallStack& drawTrace = gl.GetDrawTrace();
456   drawTrace.Enable(true);
457
458   // Stop the newActor from being rendered by changing the source actor
459   DALI_TEST_CHECK( nonRenderableActor );
460   task.SetSourceActor( nonRenderableActor );
461   DALI_TEST_CHECK( task.GetSourceActor() != actor );
462   DALI_TEST_CHECK( task.GetSourceActor() == nonRenderableActor );
463
464   // Update & Render nothing!
465   application.GetGlAbstraction().ClearBoundTextures();
466   application.SendNotification();
467   application.Render();
468
469   // Check that nothing was rendered
470   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 0, TEST_LOCATION );
471   drawTrace.Reset();
472
473   // Set newActor as the new source Actor
474   task.SetSourceActor( newActor );
475   DALI_TEST_CHECK( task.GetSourceActor() != actor );
476   DALI_TEST_CHECK( task.GetSourceActor() == newActor );
477
478   // Update & Render the newActor
479   application.GetGlAbstraction().ClearBoundTextures();
480   application.SendNotification();
481   application.Render();
482
483   // Check that the newActor was rendered
484   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION );
485   END_TEST;
486 }
487
488 int UtcDaliRenderTaskSetSourceActorOffStage(void)
489 {
490   TestApplication application;
491
492   tet_infoline("Testing RenderTask::SetSourceActor (on/off stage testing)");
493
494   Stage stage = Stage::GetCurrent();
495   RenderTaskList taskList = stage.GetRenderTaskList();
496   RenderTask task = taskList.GetTask( 0u );
497
498   Actor actor = task.GetSourceActor();
499   DALI_TEST_CHECK( actor );
500
501   TestGlAbstraction& gl = application.GetGlAbstraction();
502   TraceCallStack& drawTrace = gl.GetDrawTrace();
503   drawTrace.Enable(true);
504
505   BufferImage img = BufferImage::New( 1,1 );
506   Actor newActor = CreateRenderableActor( img );
507   newActor.SetSize(1,1);
508   task.SetSourceActor( newActor );
509   // Don't add newActor to stage yet   //'
510
511   // Update & Render with the actor initially off-stage
512   application.SendNotification();
513   application.Render();
514
515   // Check that nothing was rendered
516   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 0, TEST_LOCATION );
517
518   // Now add to stage
519   stage.Add( newActor );
520
521   // Update & Render with the actor on-stage
522   application.GetGlAbstraction().ClearBoundTextures();
523   application.SendNotification();
524   application.Render();
525
526   // Check that the newActor was rendered
527   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION );
528   drawTrace.Reset();
529
530   // Now remove from stage
531   stage.Remove( newActor );
532
533   // Update & Render with the actor off-stage
534   application.SendNotification();
535   application.Render();
536   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 0, TEST_LOCATION );
537
538   END_TEST;
539 }
540
541 int UtcDaliRenderTaskSetSourceActorEmpty(void)
542 {
543   TestApplication application;
544
545   tet_infoline("Testing RenderTask::SetSourceActor (empty handle case)");
546
547   Stage stage = Stage::GetCurrent();
548   RenderTaskList taskList = stage.GetRenderTaskList();
549   RenderTask task = taskList.GetTask( 0u );
550
551   Actor actor = task.GetSourceActor();
552   DALI_TEST_CHECK( actor );
553
554   BufferImage img = BufferImage::New( 1,1 );
555   Actor newActor = CreateRenderableActor( img );
556   newActor.SetSize(1,1);
557   stage.Add( newActor );
558
559   Actor nonRenderableActor = Actor::New();
560   stage.Add( nonRenderableActor );
561
562   // Set with empty handle
563   task.SetSourceActor( Actor() );
564   DALI_TEST_CHECK( ! task.GetSourceActor() );
565
566   TestGlAbstraction& gl = application.GetGlAbstraction();
567   TraceCallStack& drawTrace = gl.GetDrawTrace();
568   drawTrace.Enable(true);
569
570   // Update & Render nothing!
571   application.SendNotification();
572   application.Render();
573
574   // Check that nothing was rendered
575   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 0, TEST_LOCATION );
576
577   // Set with non-empty handle
578   task.SetSourceActor( newActor );
579   DALI_TEST_CHECK( task.GetSourceActor() == newActor );
580
581   // Update & Render the newActor
582   application.GetGlAbstraction().ClearBoundTextures();
583   application.SendNotification();
584   application.Render();
585
586   // Check that the newActor was rendered
587   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION );
588   END_TEST;
589 }
590
591 int UtcDaliRenderTaskGetSourceActorP01(void)
592 {
593   TestApplication application;
594
595   tet_infoline("Testing RenderTask::GetSourceActor() Check the default render task has a valid source actor");
596
597   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
598
599   RenderTask task = taskList.GetTask( 0u );
600
601   Actor actor = task.GetSourceActor();
602   DALI_TEST_CHECK( actor );
603
604   // By default the entire scene should be rendered
605   Actor root = Stage::GetCurrent().GetLayer( 0 );
606   DALI_TEST_CHECK( root == actor );
607   END_TEST;
608 }
609
610 int UtcDaliRenderTaskGetSourceActorP02(void)
611 {
612   TestApplication application;
613
614   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.");
615
616   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
617   RenderTask task = taskList.CreateTask();
618   Actor actor = Actor::New();
619   Stage::GetCurrent().Add(actor);
620   task.SetSourceActor( actor );
621
622   DALI_TEST_EQUALS( actor, task.GetSourceActor(), TEST_LOCATION );
623
624   END_TEST;
625 }
626
627 int UtcDaliRenderTaskGetSourceActorN(void)
628 {
629   TestApplication application;
630
631   tet_infoline("Testing RenderTask::GetSourceActor() Try with empty handle");
632
633   RenderTask task;
634   try
635   {
636     Actor actor = task.GetSourceActor();
637   }
638   catch (Dali::DaliException& e)
639   {
640     DALI_TEST_PRINT_ASSERT( e );
641     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
642   }
643
644   END_TEST;
645 }
646
647 int UtcDaliRenderTaskSetExclusive(void)
648 {
649   TestApplication application;
650
651   tet_infoline("Testing RenderTask::SetExclusive() Check that exclusion works");
652
653   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
654
655   // Manipulate the GenTextures behaviour, to identify different actors
656
657   std::vector<GLuint> ids;
658   ids.push_back( 8 ); // 8 = actor1
659   ids.push_back( 9 ); // 9 = actor2
660   ids.push_back( 10 ); // 10 = actor3
661   application.GetGlAbstraction().SetNextTextureIds( ids );
662
663   BufferImage img1 = BufferImage::New( 1,1 );
664   Actor actor1 = CreateRenderableActor( img1 );
665   actor1.SetSize(1,1);
666   Stage::GetCurrent().Add( actor1 );
667
668   // Update & Render actor1
669   application.SendNotification();
670   application.Render();
671
672   // Check that the actor1 was rendered
673   const std::vector<GLuint>& boundTextures = application.GetGlAbstraction().GetBoundTextures( GL_TEXTURE0 );
674   DALI_TEST_EQUALS( boundTextures.size(), 1u, TEST_LOCATION );
675
676   if ( boundTextures.size() )
677   {
678     DALI_TEST_EQUALS( boundTextures[0], 8u/*unique to actor1*/, TEST_LOCATION );
679   }
680
681   BufferImage img2 = BufferImage::New( 1,1 );
682   Actor actor2 = CreateRenderableActor( img2 );
683   actor2.SetSize(1,1);
684
685   // Force actor2 to be rendered before actor1
686   Layer layer = Layer::New();
687   Stage::GetCurrent().Add( layer );
688   layer.Add( actor2 );
689   layer.LowerToBottom();
690
691   // Update & Render
692   application.GetGlAbstraction().ClearBoundTextures();
693   application.SendNotification();
694   application.Render();
695
696   // Check that the actors were rendered
697   DALI_TEST_EQUALS( boundTextures.size(), 2u, TEST_LOCATION );
698
699   if ( boundTextures.size() )
700   {
701     DALI_TEST_EQUALS( boundTextures[0], 9u/*unique to actor2*/, TEST_LOCATION );
702     DALI_TEST_EQUALS( boundTextures[1], 8u/*unique to actor1*/, TEST_LOCATION );
703   }
704
705   BufferImage img3 = BufferImage::New( 1,1 );
706   Actor actor3 = CreateRenderableActor( img3 );
707   actor3.SetSize(1,1);
708
709   // Force actor3 to be rendered before actor2
710   layer = Layer::New();
711   Stage::GetCurrent().Add( layer );
712   layer.Add( actor3 );
713   layer.LowerToBottom();
714
715   // Update & Render all actors
716   application.GetGlAbstraction().ClearBoundTextures();
717   application.SendNotification();
718   application.Render();
719
720   // Check that the actors were rendered
721   DALI_TEST_EQUALS( boundTextures.size(), 3u, TEST_LOCATION );
722
723   if ( boundTextures.size() )
724   {
725     DALI_TEST_EQUALS( boundTextures[0], 10u/*unique to actor3*/, TEST_LOCATION );
726     DALI_TEST_EQUALS( boundTextures[1], 9u/*unique to actor2*/, TEST_LOCATION );
727     DALI_TEST_EQUALS( boundTextures[2], 8u/*unique to actor1*/, TEST_LOCATION );
728   }
729
730   // Both actors are now connected to the root node
731   // Setup 2 render-tasks - the first will render from the root-node, and the second from actor2
732
733   // Not exclusive is the default
734   RenderTask task1 = taskList.GetTask( 0u );
735   DALI_TEST_CHECK( false == task1.IsExclusive() );
736
737   RenderTask task2 = taskList.CreateTask();
738   DALI_TEST_CHECK( false == task2.IsExclusive() );
739   task2.SetSourceActor( actor2 );
740
741   // Task1 should render all actors, and task 2 should render only actor2
742
743   application.GetGlAbstraction().ClearBoundTextures();
744   application.SendNotification();
745   application.Render();
746
747   DALI_TEST_EQUALS( boundTextures.size(), 4u, TEST_LOCATION );
748
749   if ( boundTextures.size() == 4 )
750   {
751     // Test that task 1 renders actor3, then actor2 & then actor1
752     DALI_TEST_CHECK( boundTextures[0] == 10u );
753     DALI_TEST_CHECK( boundTextures[1] == 9u );
754     DALI_TEST_CHECK( boundTextures[2] == 8u );
755
756     // Test that task 2 renders actor2
757     DALI_TEST_EQUALS( boundTextures[3], 9u, TEST_LOCATION );
758   }
759
760   // Make actor2 exclusive to task2
761
762   task2.SetExclusive( true );
763   DALI_TEST_CHECK( true == task2.IsExclusive() );
764
765   // Task1 should render only actor1, and task 2 should render only actor2
766
767   application.GetGlAbstraction().ClearBoundTextures();
768   application.SendNotification();
769   application.Render();
770
771   DALI_TEST_EQUALS( boundTextures.size(), 3u, TEST_LOCATION );
772   if ( boundTextures.size() == 3 )
773   {
774     // Test that task 1 renders actor3 & actor1
775     DALI_TEST_CHECK( boundTextures[0] == 10u );
776     DALI_TEST_CHECK( boundTextures[1] == 8u );
777
778     // Test that task 2 renders actor2
779     DALI_TEST_CHECK( boundTextures[2] == 9u );
780   }
781   END_TEST;
782 }
783
784 int UtcDaliRenderTaskSetExclusive02(void)
785 {
786   TestApplication application;
787
788   tet_infoline("Testing RenderTask::SetExclusive() Check that changing from exclusive to not-exclusive works");
789
790   std::vector<GLuint> ids;
791   ids.push_back( 8 ); // 8 = actor1
792   application.GetGlAbstraction().SetNextTextureIds( ids );
793
794   BufferImage img1 = BufferImage::New( 1,1 );
795   Actor actor1 = CreateRenderableActor( img1 );
796   actor1.SetSize(1,1);
797   Stage::GetCurrent().Add( actor1 );
798
799   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
800   RenderTask task = taskList.CreateTask();
801
802   task.SetSourceActor( actor1 );
803   task.SetExclusive(true); // Actor should only render once
804
805   TestGlAbstraction& gl = application.GetGlAbstraction();
806   TraceCallStack& drawTrace = gl.GetDrawTrace();
807   drawTrace.Enable(true);
808
809   // Update & Render actor1
810   application.SendNotification();
811   application.Render();
812
813   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION );
814
815   // Set task to non-exclusive - actor1 should render twice:
816   drawTrace.Reset();
817   task.SetExclusive(false);
818   application.SendNotification();
819   application.Render();
820
821   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 2, TEST_LOCATION );
822
823   END_TEST;
824 }
825
826 int UtcDaliRenderTaskSetExclusiveN(void)
827 {
828   TestApplication application;
829
830   tet_infoline("Testing RenderTask::SetExclusive() on empty handle");
831
832   RenderTask task;
833   try
834   {
835     task.SetExclusive(true);
836   }
837   catch (Dali::DaliException& e)
838   {
839     DALI_TEST_PRINT_ASSERT( e );
840     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
841   }
842   END_TEST;
843 }
844
845 int UtcDaliRenderTaskIsExclusive01(void)
846 {
847   TestApplication application;
848
849   tet_infoline("Testing RenderTask::IsExclusive() Check default values are non-exclusive");
850
851   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
852
853   // Not exclusive is the default
854   RenderTask task = taskList.GetTask( 0u );
855   DALI_TEST_CHECK( false == task.IsExclusive() );
856
857   RenderTask newTask = taskList.CreateTask();
858   DALI_TEST_CHECK( false == newTask.IsExclusive() );
859
860   END_TEST;
861 }
862
863 int UtcDaliRenderTaskIsExclusive02(void)
864 {
865   TestApplication application;
866
867   tet_infoline("Testing RenderTask::IsExclusive() Check the getter returns set values");
868
869   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
870
871   // Not exclusive is the default
872   RenderTask newTask = taskList.CreateTask();
873   DALI_TEST_EQUALS( newTask.IsExclusive(), false, TEST_LOCATION );
874
875   newTask.SetExclusive(true);
876   DALI_TEST_EQUALS( newTask.IsExclusive(), true, TEST_LOCATION );
877   END_TEST;
878 }
879
880 int UtcDaliRenderTaskIsExclusiveN(void)
881 {
882   TestApplication application;
883
884   tet_infoline("Testing RenderTask::IsExclusive() on empty handle");
885
886   RenderTask task;
887   try
888   {
889     bool x = task.IsExclusive();
890     (void) x;
891   }
892   catch (Dali::DaliException& e)
893   {
894     DALI_TEST_PRINT_ASSERT( e );
895     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
896   }
897   END_TEST;
898 }
899
900 int UtcDaliRenderTaskSetInputEnabled(void)
901 {
902   TestApplication application;
903
904   tet_infoline("Testing RenderTask::SetInputEnabled()");
905
906   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
907
908   // Input is enabled by default
909   RenderTask task = taskList.GetTask( 0u );
910   DALI_TEST_CHECK( true == task.GetInputEnabled() );
911
912   task.SetInputEnabled( false );
913   DALI_TEST_CHECK( false == task.GetInputEnabled() );
914
915   task.SetInputEnabled( true );
916   DALI_TEST_CHECK( true == task.GetInputEnabled() );
917   END_TEST;
918 }
919
920 int UtcDaliRenderTaskGetInputEnabled(void)
921 {
922   TestApplication application;
923
924   tet_infoline("Testing RenderTask::GetInputEnabled()");
925
926   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
927
928   // Input is enabled by default
929   RenderTask task = taskList.GetTask( 0u );
930   DALI_TEST_EQUALS( true, task.GetInputEnabled(), TEST_LOCATION );
931
932   RenderTask newTask = taskList.CreateTask();
933   DALI_TEST_EQUALS( true, newTask.GetInputEnabled(), TEST_LOCATION );
934
935   newTask.SetInputEnabled(false);
936   DALI_TEST_EQUALS( false, newTask.GetInputEnabled(), TEST_LOCATION );
937
938   END_TEST;
939 }
940
941 int UtcDaliRenderTaskSetCameraActorP(void)
942 {
943   TestApplication application;
944
945   tet_infoline("Testing RenderTask::SetCameraActor()");
946
947   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
948
949   RenderTask task = taskList.GetTask( 0u );
950
951   Actor defaultCameraActor = task.GetCameraActor();
952   DALI_TEST_CHECK( defaultCameraActor );
953
954   CameraActor newCameraActor = CameraActor::New();
955   DALI_TEST_CHECK( newCameraActor );
956
957   task.SetCameraActor( newCameraActor );
958   DALI_TEST_CHECK( task.GetCameraActor() != defaultCameraActor );
959   DALI_TEST_EQUALS( task.GetCameraActor(), newCameraActor, TEST_LOCATION );
960   END_TEST;
961 }
962
963
964 int UtcDaliRenderTaskSetCameraActorN(void)
965 {
966   TestApplication application;
967
968   tet_infoline("Testing RenderTask::SetCameraActor() with empty actor handle");
969
970   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
971
972   RenderTask task = taskList.GetTask( 0u );
973
974   Actor actor = task.GetCameraActor();
975   DALI_TEST_CHECK( actor );
976
977   CameraActor cameraActor;
978
979   task.SetCameraActor( cameraActor );
980   DALI_TEST_EQUALS( (bool)task.GetCameraActor(), false, TEST_LOCATION );
981   DALI_TEST_EQUALS( task.GetCameraActor(), cameraActor, TEST_LOCATION );
982   END_TEST;
983 }
984
985
986 int UtcDaliRenderTaskGetCameraActorP(void)
987 {
988   TestApplication application;
989
990   tet_infoline("Testing RenderTask::GetCameraActor()");
991
992   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
993
994   RenderTask task = taskList.GetTask( 0u );
995
996   CameraActor actor = task.GetCameraActor();
997   DALI_TEST_CHECK( actor );
998   DALI_TEST_EQUALS( actor.GetProjectionMode(), Dali::Camera::PERSPECTIVE_PROJECTION, TEST_LOCATION );
999   DALI_TEST_GREATER( actor.GetFieldOfView(), 0.0f, TEST_LOCATION );
1000   END_TEST;
1001 }
1002
1003 int UtcDaliRenderTaskGetCameraActorN(void)
1004 {
1005   TestApplication application;
1006
1007   tet_infoline("Testing RenderTask::GetCameraActor() with empty handle");
1008   RenderTask task;
1009
1010   try
1011   {
1012     Actor actor = task.GetCameraActor();
1013   }
1014   catch (Dali::DaliException& e)
1015   {
1016     DALI_TEST_PRINT_ASSERT( e );
1017     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1018   }
1019
1020   END_TEST;
1021 }
1022
1023 int UtcDaliRenderTaskSetTargetFrameBufferP(void)
1024 {
1025   TestApplication application;
1026
1027   tet_infoline("Testing RenderTask::SetTargetFrameBuffer()");
1028
1029   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1030
1031   RenderTask task = taskList.GetTask( 0u );
1032
1033   FrameBufferImage newImage = FrameBufferImage::New();
1034   task.SetTargetFrameBuffer( newImage );
1035   DALI_TEST_CHECK( task.GetTargetFrameBuffer() == newImage );
1036   END_TEST;
1037 }
1038
1039 int UtcDaliRenderTaskSetTargetFrameBufferN(void)
1040 {
1041   TestApplication application;
1042
1043   tet_infoline("Testing RenderTask::SetTargetFrameBuffer()");
1044
1045   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1046
1047   RenderTask task = taskList.GetTask( 0u );
1048   FrameBufferImage newImage; // Empty handle
1049   task.SetTargetFrameBuffer( newImage );
1050   DALI_TEST_EQUALS( (bool)task.GetTargetFrameBuffer(), false, TEST_LOCATION );
1051   END_TEST;
1052 }
1053
1054 int UtcDaliRenderTaskGetTargetFrameBufferP(void)
1055 {
1056   TestApplication application;
1057
1058   tet_infoline("Testing RenderTask::GetTargetFrameBuffer()");
1059
1060   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1061
1062   RenderTask newTask = taskList.CreateTask();
1063   FrameBufferImage fb = FrameBufferImage::New(128, 128, Pixel::RGBA8888);
1064   newTask.SetTargetFrameBuffer( fb );
1065   DALI_TEST_EQUALS( newTask.GetTargetFrameBuffer(), fb, TEST_LOCATION );
1066   END_TEST;
1067 }
1068
1069 int UtcDaliRenderTaskGetTargetFrameBufferN(void)
1070 {
1071   TestApplication application;
1072
1073   tet_infoline("Testing RenderTask::GetTargetFrameBuffer()");
1074
1075   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1076
1077   RenderTask task = taskList.GetTask( 0u );
1078
1079   // By default render-tasks do not render off-screen
1080   FrameBufferImage image = task.GetTargetFrameBuffer();
1081   DALI_TEST_CHECK( !image );
1082
1083   END_TEST;
1084 }
1085
1086 int UtcDaliRenderTaskSetFrameBufferP(void)
1087 {
1088   TestApplication application;
1089
1090   tet_infoline("Testing RenderTask::SetFrameBuffer()");
1091
1092   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1093
1094   RenderTask task = taskList.GetTask( 0u );
1095
1096   FrameBuffer newFrameBuffer = FrameBuffer::New( 128u, 128u, FrameBuffer::Attachment::NONE );
1097   task.SetFrameBuffer( newFrameBuffer );
1098   DALI_TEST_CHECK( task.GetFrameBuffer() == newFrameBuffer );
1099   END_TEST;
1100 }
1101
1102 int UtcDaliRenderTaskSetFrameBufferN(void)
1103 {
1104   TestApplication application;
1105
1106   tet_infoline("Testing RenderTask::SetFrameBuffer()");
1107
1108   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1109
1110   RenderTask task = taskList.GetTask( 0u );
1111   FrameBuffer newFrameBuffer; // Empty handle
1112   task.SetFrameBuffer( newFrameBuffer );
1113   DALI_TEST_EQUALS( (bool)task.GetFrameBuffer(), false, TEST_LOCATION );
1114   END_TEST;
1115 }
1116
1117 int UtcDaliRenderTaskGetFrameBufferP(void)
1118 {
1119   TestApplication application;
1120
1121   tet_infoline("Testing RenderTask::GetFrameBuffer()");
1122
1123   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1124
1125   RenderTask task = taskList.GetTask( 0u );
1126
1127   FrameBuffer newFrameBuffer = FrameBuffer::New( 1u, 1u, FrameBuffer::Attachment::NONE  );
1128   task.SetFrameBuffer( newFrameBuffer );
1129   DALI_TEST_CHECK( task.GetFrameBuffer() == newFrameBuffer );
1130   END_TEST;
1131 }
1132
1133 int UtcDaliRenderTaskGetFrameBufferN(void)
1134 {
1135   TestApplication application;
1136
1137   tet_infoline("Testing RenderTask::GetFrameBuffer()");
1138
1139   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1140
1141   RenderTask task = taskList.GetTask( 0u );
1142
1143   // By default render-tasks do not render off-screen
1144   FrameBuffer frameBuffer = task.GetFrameBuffer();
1145   DALI_TEST_CHECK( !frameBuffer );
1146
1147   END_TEST;
1148 }
1149
1150 int UtcDaliRenderTaskSetScreenToFrameBufferFunctionP(void)
1151 {
1152   TestApplication application;
1153
1154   tet_infoline("Testing RenderTask::SetScreenToFrameBufferFunction()");
1155
1156   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1157
1158   RenderTask task = taskList.GetTask( 0u );
1159
1160   task.SetScreenToFrameBufferFunction( TestScreenToFrameBufferFunction );
1161
1162   Vector2 coordinates( 5, 10 );
1163   Vector2 convertedCoordinates( 6, 12 ); // + Vector(1, 2)
1164
1165   RenderTask::ScreenToFrameBufferFunction func = task.GetScreenToFrameBufferFunction();
1166   DALI_TEST_CHECK( func( coordinates ) );
1167   DALI_TEST_CHECK( coordinates == convertedCoordinates );
1168
1169   task.SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );
1170   func = task.GetScreenToFrameBufferFunction();
1171   DALI_TEST_CHECK( func( coordinates ) );
1172
1173   task.SetScreenToFrameBufferFunction( RenderTask::DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION );
1174   func = task.GetScreenToFrameBufferFunction();
1175   DALI_TEST_CHECK( ! func( coordinates ) );
1176   END_TEST;
1177 }
1178
1179 int UtcDaliRenderTaskSetScreenToFrameBufferFunctionN(void)
1180 {
1181   TestApplication application;
1182
1183   tet_infoline("Testing RenderTask::SetScreenToFrameBufferFunction()");
1184
1185   RenderTask task; // Empty handle
1186   try
1187   {
1188     task.SetScreenToFrameBufferFunction( TestScreenToFrameBufferFunction );
1189   }
1190   catch (Dali::DaliException& e)
1191   {
1192     DALI_TEST_PRINT_ASSERT( e );
1193     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1194   }
1195   END_TEST;
1196 }
1197
1198 int UtcDaliRenderTaskGetScreenToFrameBufferFunctionP(void)
1199 {
1200   TestApplication application;
1201
1202   tet_infoline("Testing RenderTask::GetScreenToFrameBufferFunction()");
1203
1204   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1205
1206   RenderTask task = taskList.GetTask( 0u );
1207
1208   Vector2 originalCoordinates( 5, 10 );
1209   Vector2 coordinates( 5, 10 );
1210
1211   RenderTask::ScreenToFrameBufferFunction func = task.GetScreenToFrameBufferFunction();
1212   DALI_TEST_CHECK( !func( coordinates ) ); // conversion should fail by default
1213   DALI_TEST_CHECK( coordinates == originalCoordinates ); // coordinates should not be modified
1214   END_TEST;
1215 }
1216
1217 int UtcDaliRenderTaskGetScreenToFrameBufferFunctionN(void)
1218 {
1219   TestApplication application;
1220
1221   tet_infoline("Testing RenderTask::GetScreenToFrameBufferFunction() on empty handle");
1222
1223   RenderTask task;
1224   try
1225   {
1226     RenderTask::ScreenToFrameBufferFunction func = task.GetScreenToFrameBufferFunction();
1227     (void) func;
1228   }
1229   catch (Dali::DaliException& e)
1230   {
1231     DALI_TEST_PRINT_ASSERT( e );
1232     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1233   }
1234   END_TEST;
1235 }
1236
1237
1238 int UtcDaliRenderTaskGetScreenToFrameBufferMappingActorP(void)
1239 {
1240   TestApplication application;
1241   tet_infoline("Testing RenderTask::GetScreenToFrameBufferMappingActor ");
1242
1243   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1244   RenderTask renderTask = taskList.CreateTask();
1245   Actor mappingActor = Actor::New();
1246   renderTask.SetScreenToFrameBufferMappingActor(mappingActor);
1247
1248   DALI_TEST_EQUALS( mappingActor, renderTask.GetScreenToFrameBufferMappingActor(), TEST_LOCATION );
1249   END_TEST;
1250 }
1251
1252
1253 int UtcDaliRenderTaskGetScreenToFrameBufferMappingActorN(void)
1254 {
1255   TestApplication application;
1256   tet_infoline("Testing RenderTask::GetScreenToFrameBufferMappingActor with empty task handle");
1257
1258   RenderTask task;
1259   try
1260   {
1261     Actor mappingActor;
1262     task.SetScreenToFrameBufferMappingActor(mappingActor);
1263   }
1264   catch (Dali::DaliException& e)
1265   {
1266     DALI_TEST_PRINT_ASSERT( e );
1267     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1268   }
1269   END_TEST;
1270 }
1271
1272 int UtcDaliRenderTaskGetScreenToFrameBufferMappingActor02N(void)
1273 {
1274   TestApplication application;
1275   tet_infoline("Testing RenderTask::GetScreenToFrameBufferMappingActor with empty task handle");
1276
1277   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1278   RenderTask renderTask = taskList.CreateTask();
1279   Actor actor;
1280   renderTask.SetScreenToFrameBufferMappingActor(actor);
1281
1282   DALI_TEST_EQUALS( (bool)renderTask.GetScreenToFrameBufferMappingActor(), false, TEST_LOCATION);
1283   END_TEST;
1284 }
1285
1286 int UtcDaliRenderTaskGetViewportP01(void)
1287 {
1288   TestApplication application;
1289
1290   tet_infoline("Testing RenderTask::GetViewport() on default task");
1291
1292   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1293   RenderTask task = taskList.GetTask( 0u );
1294   Viewport viewport = task.GetViewport();
1295
1296   // By default the viewport should match the stage width/height
1297   Vector2 stageSize = Stage::GetCurrent().GetSize();
1298   Viewport expectedViewport( 0, 0, stageSize.width, stageSize.height );
1299   DALI_TEST_CHECK( viewport == expectedViewport );
1300   END_TEST;
1301 }
1302
1303 int UtcDaliRenderTaskGetViewportP02(void)
1304 {
1305   TestApplication application;
1306
1307   tet_infoline("Testing RenderTask::GetViewport() on new task");
1308
1309   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1310   RenderTask task = taskList.CreateTask();
1311   Viewport viewport = task.GetViewport();
1312
1313   // By default the viewport should match the stage width/height
1314   Vector2 stageSize = Stage::GetCurrent().GetSize();
1315   Viewport expectedViewport( 0, 0, stageSize.width, stageSize.height );
1316   DALI_TEST_CHECK( viewport == expectedViewport );
1317   END_TEST;
1318 }
1319
1320 int UtcDaliRenderTaskGetViewportN(void)
1321 {
1322   TestApplication application;
1323
1324   tet_infoline("Testing RenderTask::GetViewport() on empty handle");
1325
1326   RenderTask task;
1327   try
1328   {
1329     Viewport viewport = task.GetViewport();
1330     (void) viewport;
1331   }
1332   catch (Dali::DaliException& e)
1333   {
1334     DALI_TEST_PRINT_ASSERT( e );
1335     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1336   }
1337   END_TEST;
1338 }
1339
1340
1341 int UtcDaliRenderTaskSetViewportP(void)
1342 {
1343   TestApplication application;
1344
1345   tet_infoline("Testing RenderTask::SetViewport()");
1346
1347   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1348
1349   RenderTask task = taskList.GetTask( 0u );
1350   Vector2 stageSize = Stage::GetCurrent().GetSize();
1351   Viewport newViewport( 0, 0, stageSize.width * 0.5f, stageSize.height * 0.5f );
1352   task.SetViewport( newViewport );
1353
1354   // Update (viewport is a property)
1355   application.SendNotification();
1356   application.Render();
1357
1358   DALI_TEST_CHECK( task.GetViewport() == newViewport );
1359   END_TEST;
1360 }
1361
1362 int UtcDaliRenderTaskSetViewportN(void)
1363 {
1364   TestApplication application;
1365
1366   tet_infoline("Testing RenderTask::SetViewport()");
1367
1368   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1369
1370   RenderTask task;
1371   try
1372   {
1373     Vector2 stageSize = Stage::GetCurrent().GetSize();
1374     Viewport newViewport( 0, 0, stageSize.width * 0.5f, stageSize.height * 0.5f );
1375     task.SetViewport( newViewport );
1376   }
1377   catch (Dali::DaliException& e)
1378   {
1379     DALI_TEST_PRINT_ASSERT( e );
1380     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1381   }
1382
1383   END_TEST;
1384 }
1385
1386
1387 int UtcDaliRenderTaskSetViewportPosition(void)
1388 {
1389   TestApplication application;
1390
1391   tet_infoline("Testing RenderTask::SetViewportPosition()");
1392
1393   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1394
1395   RenderTask task = taskList.GetTask( 0u );
1396
1397   Viewport viewport = task.GetViewport();
1398
1399   // By default the viewport should match the stage width/height
1400
1401   Vector2 stageSize = Stage::GetCurrent().GetSize();
1402   Viewport expectedViewport( 0, 0, stageSize.width, stageSize.height );
1403   DALI_TEST_CHECK( viewport == expectedViewport );
1404
1405   // 'Setter' test
1406   Vector2 newPosition(25.0f, 50.0f);
1407   task.SetViewportPosition( newPosition );
1408
1409   // Update (viewport is a property)
1410   application.SendNotification();
1411   application.Render();
1412
1413   DALI_TEST_EQUALS( task.GetCurrentViewportPosition(), newPosition, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1414
1415   // Set by Property test
1416   Vector2 newPosition2(32.0f, 32.0f);
1417   task.SetProperty( RenderTask::Property::VIEWPORT_POSITION, newPosition2 );
1418   DALI_TEST_EQUALS( task.GetProperty< Vector2 >( RenderTask::Property::VIEWPORT_POSITION ), newPosition2, TEST_LOCATION );
1419   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector2 >( task, RenderTask::Property::VIEWPORT_POSITION ), newPosition, TEST_LOCATION ); // still the old position
1420
1421   // Update
1422   application.SendNotification();
1423   application.Render();
1424
1425   DALI_TEST_EQUALS( task.GetCurrentViewportPosition(), newPosition2, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1426   DALI_TEST_EQUALS( task.GetProperty< Vector2 >( RenderTask::Property::VIEWPORT_POSITION ), newPosition2, TEST_LOCATION );
1427   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector2 >( task, RenderTask::Property::VIEWPORT_POSITION ), newPosition2, TEST_LOCATION );
1428
1429   Vector2 newPosition3(64.0f, 0.0f);
1430   Animation animation = Animation::New(1.0f);
1431   animation.AnimateTo( Property( task, RenderTask::Property::VIEWPORT_POSITION ), newPosition3, AlphaFunction::LINEAR );
1432   animation.Play();
1433
1434   // Perform 1000ms worth of updates at which point animation should have completed.
1435   Wait(application, 1000);
1436   DALI_TEST_EQUALS( task.GetCurrentViewportPosition(), newPosition3, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1437   END_TEST;
1438 }
1439
1440 int UtcDaliRenderTaskSetViewportSize(void)
1441 {
1442   TestApplication application;
1443
1444   tet_infoline("Testing RenderTask::SetViewportSize()");
1445
1446   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1447
1448   RenderTask task = taskList.GetTask( 0u );
1449
1450   Viewport viewport = task.GetViewport();
1451
1452   // By default the viewport should match the stage width/height
1453
1454   Vector2 stageSize = Stage::GetCurrent().GetSize();
1455   Viewport expectedViewport( 0, 0, stageSize.width, stageSize.height );
1456   DALI_TEST_CHECK( viewport == expectedViewport );
1457
1458   Vector2 newSize(128.0f, 64.0f);
1459   task.SetViewportSize( newSize );
1460
1461   // Update (viewport is a property)
1462   application.SendNotification();
1463   application.Render();
1464
1465   DALI_TEST_EQUALS( task.GetCurrentViewportSize(), newSize, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1466
1467   // Set by Property test
1468   Vector2 newSize2(50.0f, 50.0f);
1469   task.SetProperty( RenderTask::Property::VIEWPORT_SIZE, newSize2 );
1470   DALI_TEST_EQUALS( task.GetProperty< Vector2 >( RenderTask::Property::VIEWPORT_SIZE ), newSize2, TEST_LOCATION );
1471   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector2 >( task, RenderTask::Property::VIEWPORT_SIZE ), newSize, TEST_LOCATION ); // still the old position
1472
1473   // Update
1474   application.SendNotification();
1475   application.Render();
1476
1477   DALI_TEST_EQUALS( task.GetCurrentViewportSize(), newSize2, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1478   DALI_TEST_EQUALS( task.GetProperty< Vector2 >( RenderTask::Property::VIEWPORT_SIZE ), newSize2, TEST_LOCATION );
1479   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector2 >( task, RenderTask::Property::VIEWPORT_SIZE ), newSize2, TEST_LOCATION );
1480
1481   Vector2 newSize3(10.0f, 10.0f);
1482   Animation animation = Animation::New(1.0f);
1483   animation.AnimateTo( Property( task, RenderTask::Property::VIEWPORT_SIZE ), newSize3, AlphaFunction::LINEAR );
1484   animation.Play();
1485
1486   // Perform 1000ms worth of updates at which point animation should have completed.
1487   Wait(application, 1000);
1488   DALI_TEST_EQUALS( task.GetCurrentViewportSize(), newSize3, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1489
1490   END_TEST;
1491 }
1492
1493 int UtcDaliRenderTaskSetClearColorP(void)
1494 {
1495   TestApplication application;
1496
1497   tet_infoline("Testing RenderTask::SetClearColor()");
1498
1499   Vector4 testColor( 1.0f, 2.0f, 3.0f, 4.0f );
1500   Vector4 testColor2( 5.0f, 6.0f, 7.0f, 8.0f );
1501
1502   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1503
1504   RenderTask task = taskList.GetTask( 0u );
1505   DALI_TEST_CHECK( task.GetClearColor() != testColor );
1506
1507   task.SetClearColor( testColor );
1508
1509   // Wait a frame.
1510   Wait(application);
1511
1512   DALI_TEST_EQUALS( task.GetClearColor(), testColor, TEST_LOCATION );
1513
1514   task.SetProperty( RenderTask::Property::CLEAR_COLOR, testColor2 );
1515   DALI_TEST_EQUALS( task.GetProperty< Vector4 >( RenderTask::Property::CLEAR_COLOR ), testColor2, TEST_LOCATION );
1516   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector4 >( task, RenderTask::Property::CLEAR_COLOR ), testColor, TEST_LOCATION ); // still the old color
1517
1518   // Wait a frame.
1519   Wait(application);
1520
1521   DALI_TEST_EQUALS( task.GetClearColor(), testColor2, TEST_LOCATION );
1522   DALI_TEST_EQUALS( task.GetProperty< Vector4 >( RenderTask::Property::CLEAR_COLOR ), testColor2, TEST_LOCATION );
1523   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector4 >( task, RenderTask::Property::CLEAR_COLOR ), testColor2, TEST_LOCATION );
1524   END_TEST;
1525 }
1526
1527 int UtcDaliRenderTaskSetClearColorN(void)
1528 {
1529   TestApplication application;
1530
1531   tet_infoline("Testing RenderTask::SetClearColor() on empty handle");
1532
1533   RenderTask task;
1534   try
1535   {
1536     task.SetClearColor( Vector4::ZERO );
1537   }
1538   catch (Dali::DaliException& e)
1539   {
1540     DALI_TEST_PRINT_ASSERT( e );
1541     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1542   }
1543   END_TEST;
1544 }
1545
1546 int UtcDaliRenderTaskGetClearColorP(void)
1547 {
1548   TestApplication application;
1549
1550   tet_infoline("Testing RenderTask::GetClearColor()");
1551
1552   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1553   RenderTask task = taskList.GetTask( 0u );
1554   DALI_TEST_EQUALS( task.GetClearColor(), RenderTask::DEFAULT_CLEAR_COLOR, TEST_LOCATION );
1555   END_TEST;
1556 }
1557
1558 int UtcDaliRenderTaskGetClearColorN(void)
1559 {
1560   TestApplication application;
1561
1562   tet_infoline("Testing RenderTask::GetClearColor()");
1563
1564   RenderTask task;
1565   try
1566   {
1567     Vector4 color = task.GetClearColor();
1568     (void) color;
1569   }
1570   catch (Dali::DaliException& e)
1571   {
1572     DALI_TEST_PRINT_ASSERT( e );
1573     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1574   }
1575   END_TEST;
1576 }
1577
1578 int UtcDaliRenderTaskSetClearEnabledP(void)
1579 {
1580   TestApplication application;
1581
1582   tet_infoline("Testing RenderTask::SetClearEnabled()");
1583
1584   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1585
1586   RenderTask task = taskList.GetTask( 0u );
1587   DALI_TEST_CHECK( !task.GetClearEnabled() ); // defaults to false
1588
1589   task.SetClearEnabled( true );
1590   DALI_TEST_EQUALS( task.GetClearEnabled(), true, TEST_LOCATION );
1591
1592   task.SetClearEnabled( false );
1593   DALI_TEST_EQUALS( task.GetClearEnabled(), false, TEST_LOCATION );
1594   END_TEST;
1595 }
1596
1597 int UtcDaliRenderTaskSetClearEnabledN(void)
1598 {
1599   TestApplication application;
1600
1601   tet_infoline("Testing RenderTask::SetClearEnabled() with empty handle");
1602
1603   RenderTask task;
1604   try
1605   {
1606     task.SetClearEnabled(true);
1607   }
1608   catch (Dali::DaliException& e)
1609   {
1610     DALI_TEST_PRINT_ASSERT( e );
1611     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1612   }
1613   END_TEST;
1614 }
1615
1616 int UtcDaliRenderTaskGetClearEnabledP(void)
1617 {
1618   TestApplication application;
1619
1620   tet_infoline("Testing RenderTask::GetClearEnabled()");
1621
1622   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1623
1624   RenderTask task = taskList.GetTask( 0u );
1625   DALI_TEST_CHECK( !task.GetClearEnabled() ); // defaults to false
1626   END_TEST;
1627 }
1628
1629
1630 int UtcDaliRenderTaskGetClearEnabledN(void)
1631 {
1632   TestApplication application;
1633
1634   tet_infoline("Testing RenderTask::GetClearEnabled() with empty handle");
1635
1636   RenderTask task;
1637   try
1638   {
1639     bool x = task.GetClearEnabled();
1640     (void) x;
1641   }
1642   catch (Dali::DaliException& e)
1643   {
1644     DALI_TEST_PRINT_ASSERT( e );
1645     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1646   }
1647   END_TEST;
1648 }
1649
1650 int UtcDaliRenderTaskSetCullModeP(void)
1651 {
1652   TestApplication application;
1653
1654   tet_infoline("Testing RenderTask::SetCullMode()");
1655
1656   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1657   RenderTask task = taskList.GetTask( 0u );
1658   DALI_TEST_EQUALS( task.GetCullMode(), true, TEST_LOCATION );
1659
1660   task.SetCullMode( false );
1661
1662   DALI_TEST_EQUALS( task.GetCullMode(), false, TEST_LOCATION );
1663
1664   END_TEST;
1665 }
1666
1667 int UtcDaliRenderTaskSetCullModeN(void)
1668 {
1669   TestApplication application;
1670
1671   tet_infoline("Testing RenderTask::SetCullMode() on empty handle");
1672
1673   RenderTask task;
1674   try
1675   {
1676     task.SetCullMode( false );
1677   }
1678   catch (Dali::DaliException& e)
1679   {
1680     DALI_TEST_PRINT_ASSERT( e );
1681     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1682   }
1683   END_TEST;
1684 }
1685
1686 int UtcDaliRenderTaskGetCullModeP(void)
1687 {
1688   TestApplication application;
1689
1690   tet_infoline("Testing RenderTask::GetCullMode()");
1691
1692   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1693   RenderTask task = taskList.GetTask( 0u );
1694   DALI_TEST_EQUALS( task.GetCullMode(), true, TEST_LOCATION );
1695   END_TEST;
1696 }
1697
1698 int UtcDaliRenderTaskGetCullModeN(void)
1699 {
1700   TestApplication application;
1701
1702   tet_infoline("Testing RenderTask::GetCullMode() with empty handle");
1703
1704   RenderTask task;
1705   try
1706   {
1707     bool x = task.GetCullMode();
1708     (void) x;
1709   }
1710   catch (Dali::DaliException& e)
1711   {
1712     DALI_TEST_PRINT_ASSERT( e );
1713     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1714   }
1715   END_TEST;
1716 }
1717
1718
1719 int UtcDaliRenderTaskSetRefreshRate(void)
1720 {
1721   TestApplication application;
1722
1723   tet_infoline("Testing RenderTask::SetRefreshRate()");
1724
1725   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1726
1727   // By default tasks will be processed every frame
1728   RenderTask task = taskList.GetTask( 0u );
1729   DALI_TEST_CHECK( RenderTask::REFRESH_ALWAYS == task.GetRefreshRate() );
1730
1731   task.SetRefreshRate( 2u ); // every-other frame
1732   DALI_TEST_CHECK( 2u == task.GetRefreshRate() );
1733
1734   task.SetRefreshRate( RenderTask::REFRESH_ALWAYS );
1735   DALI_TEST_CHECK( RenderTask::REFRESH_ALWAYS == task.GetRefreshRate() );
1736   END_TEST;
1737 }
1738
1739 int UtcDaliRenderTaskGetRefreshRate(void)
1740 {
1741   TestApplication application;
1742
1743   tet_infoline("Testing RenderTask::GetRefreshRate()");
1744
1745   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1746
1747   // By default tasks will be processed every frame
1748   RenderTask task = taskList.GetTask( 0u );
1749   DALI_TEST_CHECK( RenderTask::REFRESH_ALWAYS == task.GetRefreshRate() );
1750
1751   RenderTask newTask = taskList.CreateTask();
1752   DALI_TEST_CHECK( RenderTask::REFRESH_ALWAYS == newTask.GetRefreshRate() );
1753   END_TEST;
1754 }
1755
1756 int UtcDaliRenderTaskSignalFinished(void)
1757 {
1758   TestApplication application;
1759
1760   tet_infoline("Testing RenderTask::SignalFinished()");
1761
1762   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1763   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
1764
1765   CameraActor offscreenCameraActor = CameraActor::New();
1766
1767   Stage::GetCurrent().Add( offscreenCameraActor );
1768
1769   BufferImage image = BufferImage::New( 10, 10 );
1770   image.Update();
1771   Actor rootActor = CreateRenderableActor( image );
1772   rootActor.SetSize( 10, 10 );
1773   Stage::GetCurrent().Add( rootActor );
1774
1775   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1776   NativeImageInterfacePtr testNativeImagePtr = TestNativeImage::New(10, 10);
1777   FrameBufferImage frameBufferImage = FrameBufferImage::New( *testNativeImagePtr.Get() );
1778
1779   RenderTask newTask = taskList.CreateTask();
1780   newTask.SetCameraActor( offscreenCameraActor );
1781   newTask.SetSourceActor( rootActor );
1782   newTask.SetInputEnabled( false );
1783   newTask.SetClearColor( Vector4( 0.f, 0.f, 0.f, 0.f ) );
1784   newTask.SetClearEnabled( true );
1785   newTask.SetExclusive( true );
1786   newTask.SetRefreshRate( RenderTask::REFRESH_ONCE );
1787   newTask.SetTargetFrameBuffer( frameBufferImage );
1788   newTask.SetProperty( RenderTask::Property::REQUIRES_SYNC, true );
1789
1790   bool finished = false;
1791   RenderTaskFinished renderTaskFinished( finished );
1792   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1793
1794   // Flush the queue and render.
1795   application.SendNotification();
1796
1797   // 1 render to process render task, then wait for sync before finished msg is sent
1798   // from update to the event thread.
1799
1800   application.Render();
1801   application.SendNotification();
1802   DALI_TEST_CHECK( !finished );
1803
1804   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
1805   DALI_TEST_CHECK( lastSyncObj != NULL );
1806
1807   application.Render();
1808   DALI_TEST_EQUALS( (Integration::KeepUpdating::Reasons)(application.GetUpdateStatus() & Integration::KeepUpdating::RENDER_TASK_SYNC), Integration::KeepUpdating::RENDER_TASK_SYNC, TEST_LOCATION );
1809   application.SendNotification();
1810   DALI_TEST_CHECK( !finished );
1811
1812   application.Render();
1813   DALI_TEST_EQUALS( (Integration::KeepUpdating::Reasons)(application.GetUpdateStatus() & Integration::KeepUpdating::RENDER_TASK_SYNC), Integration::KeepUpdating::RENDER_TASK_SYNC, TEST_LOCATION );
1814   application.SendNotification();
1815   DALI_TEST_CHECK( ! finished );
1816
1817   sync.SetObjectSynced( lastSyncObj, true );
1818
1819   application.Render();
1820   application.SendNotification();
1821   DALI_TEST_CHECK( !finished );
1822
1823   application.Render();
1824   application.SendNotification();
1825   DALI_TEST_CHECK( finished );
1826
1827   DALI_TEST_EQUALS( application.GetUpdateStatus(), 0, TEST_LOCATION );
1828   END_TEST;
1829 }
1830
1831
1832 int UtcDaliRenderTaskContinuous01(void)
1833 {
1834   TestApplication application;
1835
1836   tet_infoline("Testing RenderTask Render Continuous using loading image\nPRE: render task not ready (source actor not staged)\nPOST:continuous renders, no Finished signal");
1837
1838   // SETUP AN OFFSCREEN RENDER TASK
1839   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1840   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1841   drawTrace.Enable(true);
1842
1843   Actor rootActor = Actor::New();
1844   Stage::GetCurrent().Add( rootActor );
1845
1846   CameraActor offscreenCameraActor = CameraActor::New();
1847   Stage::GetCurrent().Add( offscreenCameraActor );
1848
1849   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
1850
1851   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1852   bool finished = false;
1853   RenderTaskFinished renderTaskFinished( finished );
1854   application.SendNotification();
1855
1856   // START PROCESS/RENDER                     Input,    Expected  Input, Expected, KeepUpdating
1857   DALI_TEST_CHECK( UpdateRender(application,  drawTrace, false,   finished, false, false, __LINE__ ) );
1858   application.GetPlatform().ClearReadyResources();
1859
1860   // ADD SOURCE ACTOR TO STAGE - expect continuous renders to start, no finished signal
1861   Stage::GetCurrent().Add(secondRootActor);
1862   application.SendNotification();
1863
1864   // CONTINUE PROCESS/RENDER                  Input,    Expected  Input,    Expected
1865   DALI_TEST_CHECK( UpdateRender(application,  drawTrace, true,    finished, false, false, __LINE__ ) );
1866   END_TEST;
1867 }
1868
1869
1870 int UtcDaliRenderTaskContinuous02(void)
1871 {
1872   TestApplication application;
1873
1874   tet_infoline("Testing RenderTask Render Continuous using loading image\nPRE: render task not ready (source actor not visible)\nPOST:continuous renders, no Finished signal");
1875
1876   // SETUP AN OFFSCREEN RENDER TASK
1877   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1878   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1879   drawTrace.Enable(true);
1880
1881   Actor rootActor = Actor::New();
1882   Stage::GetCurrent().Add( rootActor );
1883
1884   CameraActor offscreenCameraActor = CameraActor::New();
1885   Stage::GetCurrent().Add( offscreenCameraActor );
1886
1887   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
1888   Stage::GetCurrent().Add(secondRootActor);
1889   secondRootActor.SetVisible(false);
1890
1891   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1892   bool finished = false;
1893   RenderTaskFinished renderTaskFinished( finished );
1894   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1895   application.SendNotification();
1896
1897   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected, KeepUpdating
1898   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, false, __LINE__ ) );
1899   application.GetPlatform().ClearReadyResources();
1900
1901   // MAKE SOURCE ACTOR VISIBLE - expect continuous renders to start, no finished signal
1902   secondRootActor.SetVisible(true);
1903   application.SendNotification();
1904
1905   // CONTINUE PROCESS/RENDER                 Input,    Expected  Input,    Expected
1906   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
1907   END_TEST;
1908 }
1909
1910 int UtcDaliRenderTaskContinuous03(void)
1911 {
1912   TestApplication application;
1913
1914   tet_infoline("Testing RenderTask Render Continuous using loading image\nPRE: render task not ready (camera actor not staged)\nPOST:continuous renders, no Finished signal");
1915
1916   // SETUP AN OFFSCREEN RENDER TASK
1917   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1918   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1919   drawTrace.Enable(true);
1920
1921   Actor rootActor = Actor::New();
1922   Stage::GetCurrent().Add( rootActor );
1923
1924   CameraActor offscreenCameraActor = CameraActor::New();
1925   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
1926   Stage::GetCurrent().Add(secondRootActor);
1927
1928   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1929   bool finished = false;
1930   RenderTaskFinished renderTaskFinished( finished );
1931   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1932   application.SendNotification();
1933
1934   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1935   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, false, __LINE__ ) );
1936   application.GetPlatform().ClearReadyResources();
1937
1938   // ADD CAMERA ACTOR TO STAGE - expect continuous renders to start, no finished signal
1939   Stage::GetCurrent().Add( offscreenCameraActor );
1940   application.SendNotification();
1941
1942   // CONTINUE PROCESS/RENDER                 Input,    Expected  Input,    Expected
1943   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
1944   END_TEST;
1945 }
1946
1947
1948 int UtcDaliRenderTaskContinuous04(void)
1949 {
1950   TestApplication application;
1951
1952   tet_infoline("Testing RenderTask Render Continuous using loaded image");
1953
1954   // SETUP AN OFFSCREEN RENDER TASK
1955   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1956   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1957   drawTrace.Enable(true);
1958
1959   Actor rootActor = Actor::New();
1960   Stage::GetCurrent().Add( rootActor );
1961
1962   CameraActor offscreenCameraActor = CameraActor::New();
1963   Stage::GetCurrent().Add( offscreenCameraActor );
1964   Actor secondRootActor = CreateRenderableActorFailed(application, "aFile.jpg");
1965   Stage::GetCurrent().Add(secondRootActor);
1966
1967   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1968   bool finished = false;
1969   RenderTaskFinished renderTaskFinished( finished );
1970   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1971   application.SendNotification();
1972
1973   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1974   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,   finished, false, false, __LINE__ ) );
1975   END_TEST;
1976 }
1977
1978 int UtcDaliRenderTaskOnce01(void)
1979 {
1980   TestApplication application;
1981
1982   tet_infoline("Testing RenderTask Render Once GlSync, using loaded image");
1983
1984   // SETUP AN OFFSCREEN RENDER TASK
1985   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1986   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
1987   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1988   drawTrace.Enable(true);
1989
1990   Actor rootActor = Actor::New();
1991   Stage::GetCurrent().Add( rootActor );
1992
1993   CameraActor offscreenCameraActor = CameraActor::New();
1994   Stage::GetCurrent().Add( offscreenCameraActor );
1995   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
1996
1997   Stage::GetCurrent().Add(secondRootActor);
1998
1999   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, true);
2000   bool finished = false;
2001   RenderTaskFinished renderTaskFinished( finished );
2002   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2003   application.SendNotification();
2004
2005   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,   finished, false, true, __LINE__  ) );
2006
2007   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2008   DALI_TEST_CHECK( lastSyncObj != NULL );
2009   sync.SetObjectSynced( lastSyncObj, true );
2010
2011   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__  ) );
2012   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__  ) );
2013   END_TEST;
2014 }
2015
2016 int UtcDaliRenderTaskOnce02(void)
2017 {
2018   TestApplication application;
2019
2020   tet_infoline("Testing RenderTask Render Once GlSync, using Mesh which accesses texture through sampler with loaded image.\n");
2021
2022   // SETUP AN OFFSCREEN RENDER TASK
2023   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2024   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2025   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2026   drawTrace.Enable(true);
2027
2028   Actor rootActor = Actor::New();
2029   Stage::GetCurrent().Add( rootActor );
2030
2031   CameraActor offscreenCameraActor = CameraActor::New();
2032   Stage::GetCurrent().Add( offscreenCameraActor );
2033
2034   Shader shader = CreateShader();
2035   Image image = CreateResourceImage(application, "aFile.jpg");
2036   TextureSet textureSet = CreateTextureSet( image );
2037
2038   Geometry geometry = CreateQuadGeometry();
2039   Renderer renderer = Renderer::New(geometry, shader);
2040   renderer.SetTextures( textureSet );
2041   Actor secondRootActor = Actor::New();
2042   secondRootActor.AddRenderer(renderer);
2043   secondRootActor.SetSize(100, 100);
2044   Stage::GetCurrent().Add(secondRootActor);
2045
2046   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, true);
2047   bool finished = false;
2048   RenderTaskFinished renderTaskFinished( finished );
2049   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2050   application.SendNotification();
2051
2052   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,   finished, false, true, __LINE__  ) );
2053
2054   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2055   DALI_TEST_CHECK( lastSyncObj != NULL );
2056   sync.SetObjectSynced( lastSyncObj, true );
2057
2058   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__  ) );
2059   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__  ) );
2060
2061    END_TEST;
2062 }
2063
2064 int UtcDaliRenderTaskOnce03(void)
2065 {
2066   TestApplication application;
2067
2068   tet_infoline("Testing RenderTask Render Once GlSync, using loaded image. Switch from render always after ready to render once\n");
2069
2070   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2071   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2072   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2073   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2074   drawTrace.Enable(true);
2075
2076   Actor rootActor = Actor::New();
2077   Stage::GetCurrent().Add( rootActor );
2078
2079   CameraActor offscreenCameraActor = CameraActor::New();
2080   Stage::GetCurrent().Add( offscreenCameraActor );
2081   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2082   Stage::GetCurrent().Add(secondRootActor);
2083
2084   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
2085   bool finished = false;
2086   RenderTaskFinished renderTaskFinished( finished );
2087   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2088   application.SendNotification();
2089
2090   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2091
2092   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2093   application.SendNotification();
2094
2095   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,   finished, false, true, __LINE__  ) );
2096
2097   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2098   DALI_TEST_CHECK( lastSyncObj != NULL );
2099   sync.SetObjectSynced( lastSyncObj, true );
2100
2101   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__  ) );
2102   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__  ) );
2103
2104   END_TEST;
2105 }
2106
2107
2108 int UtcDaliRenderTaskOnce04(void)
2109 {
2110   TestApplication application;
2111   tet_infoline("Testing RenderTask Render Once GlSync, using Mesh which accesses texture through sampler with loaded image.\n"
2112                "Switch from render always after ready to render once\n"
2113               );
2114
2115   // SETUP AN OFFSCREEN RENDER TASK
2116   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2117   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2118   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2119   drawTrace.Enable(true);
2120
2121   Actor rootActor = Actor::New();
2122   Stage::GetCurrent().Add( rootActor );
2123
2124   CameraActor offscreenCameraActor = CameraActor::New();
2125   Stage::GetCurrent().Add( offscreenCameraActor );
2126
2127   Shader shader = CreateShader();
2128   Image image = CreateResourceImage(application, "aFile.jpg");
2129   TextureSet textureSet = CreateTextureSet( image );
2130
2131   Geometry geometry = CreateQuadGeometry();
2132   Renderer renderer = Renderer::New(geometry, shader);
2133   renderer.SetTextures( textureSet );
2134   Actor secondRootActor = Actor::New();
2135   secondRootActor.AddRenderer(renderer);
2136   secondRootActor.SetSize(100, 100);
2137   Stage::GetCurrent().Add(secondRootActor);
2138
2139   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
2140   bool finished = false;
2141   RenderTaskFinished renderTaskFinished( finished );
2142   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2143   application.SendNotification();
2144
2145   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2146
2147   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2148   application.SendNotification();
2149
2150   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,   finished, false, true, __LINE__  ) );
2151
2152   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2153   DALI_TEST_CHECK( lastSyncObj != NULL );
2154   sync.SetObjectSynced( lastSyncObj, true );
2155
2156   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__  ) );
2157   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__  ) );
2158
2159   END_TEST;
2160 }
2161
2162 int UtcDaliRenderTaskOnceNoSync01(void)
2163 {
2164   TestApplication application;
2165
2166   tet_infoline("Testing RenderTask Render Once, \nPRE: Resources ready\nPOST: Finished signal sent once only");
2167
2168   // SETUP AN OFFSCREEN RENDER TASK
2169   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2170   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2171   drawTrace.Enable(true);
2172
2173   Actor rootActor = Actor::New();
2174   Stage::GetCurrent().Add( rootActor );
2175
2176   CameraActor offscreenCameraActor = CameraActor::New();
2177   Stage::GetCurrent().Add( offscreenCameraActor );
2178   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2179   Stage::GetCurrent().Add(secondRootActor);
2180
2181   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, false);
2182   bool finished = false;
2183   RenderTaskFinished renderTaskFinished( finished );
2184   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2185   application.SendNotification();
2186
2187   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2188   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__ ) );
2189   END_TEST;
2190 }
2191
2192 int UtcDaliRenderTaskOnceNoSync02(void)
2193 {
2194   TestApplication application;
2195
2196   tet_infoline("Testing RenderTask Render Once, using Mesh which accesses texture through sampler with loaded image.\n"
2197                "PRE: Resources ready\nPOST: Finished signal sent once only");
2198   // SETUP AN OFFSCREEN RENDER TASK
2199   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2200   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2201   drawTrace.Enable(true);
2202
2203   Actor rootActor = Actor::New();
2204   Stage::GetCurrent().Add( rootActor );
2205
2206   CameraActor offscreenCameraActor = CameraActor::New();
2207   Stage::GetCurrent().Add( offscreenCameraActor );
2208
2209   Shader shader = CreateShader();
2210   Image image = CreateResourceImage(application, "aFile.jpg");
2211   TextureSet textureSet = CreateTextureSet( image );
2212
2213   Geometry geometry = CreateQuadGeometry();
2214   Renderer renderer = Renderer::New(geometry, shader);
2215   renderer.SetTextures( textureSet );
2216   Actor secondRootActor = Actor::New();
2217   secondRootActor.AddRenderer(renderer);
2218   secondRootActor.SetSize(100, 100);
2219   Stage::GetCurrent().Add(secondRootActor);
2220
2221   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, false);
2222   bool finished = false;
2223   RenderTaskFinished renderTaskFinished( finished );
2224   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2225   application.SendNotification();
2226
2227   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2228   application.GetPlatform().ClearReadyResources();
2229   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__ ) );
2230
2231   END_TEST;
2232 }
2233
2234 int UtcDaliRenderTaskOnceNoSync03(void)
2235 {
2236   TestApplication application;
2237
2238   tet_infoline("Testing RenderTask Render Once, using loaded image. Switch from render always after ready to render once\n"
2239                "PRE: Render task ready, Image loaded\n"
2240                "POST: Finished signal sent only once");
2241
2242   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2243   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2244   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2245   drawTrace.Enable(true);
2246
2247   Actor rootActor = Actor::New();
2248   Stage::GetCurrent().Add( rootActor );
2249
2250   CameraActor offscreenCameraActor = CameraActor::New();
2251   Stage::GetCurrent().Add( offscreenCameraActor );
2252   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2253   Stage::GetCurrent().Add(secondRootActor);
2254
2255   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2256   bool finished = false;
2257   RenderTaskFinished renderTaskFinished( finished );
2258   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2259   application.SendNotification();
2260
2261   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2262
2263   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2264   application.SendNotification(); //         Input,    Expected  Input,    Expected
2265   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2266   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__ ) );
2267   END_TEST;
2268 }
2269
2270 int UtcDaliRenderTaskOnceNoSync04(void)
2271 {
2272   TestApplication application;
2273
2274   tet_infoline("Testing RenderTask Render Once, using Mesh which accesses texture through sampler with loading image.\n"
2275                "Switch from render always after ready to render once\n"
2276                "PRE: Render task ready, Image not loaded\n"
2277                "POST: Finished signal sent only once");
2278
2279   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2280   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2281   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2282   drawTrace.Enable(true);
2283
2284   Actor rootActor = Actor::New();
2285   Stage::GetCurrent().Add( rootActor );
2286
2287   CameraActor offscreenCameraActor = CameraActor::New();
2288   Stage::GetCurrent().Add( offscreenCameraActor );
2289
2290   Shader shader = CreateShader();
2291   Image image = CreateResourceImage(application, "aFile.jpg");
2292   TextureSet textureSet = CreateTextureSet( image );
2293
2294   Geometry geometry = CreateQuadGeometry();
2295   Renderer renderer = Renderer::New(geometry, shader);
2296   renderer.SetTextures( textureSet );
2297   Actor secondRootActor = Actor::New();
2298   secondRootActor.AddRenderer(renderer);
2299   secondRootActor.SetSize(100, 100);
2300   Stage::GetCurrent().Add(secondRootActor);
2301
2302
2303   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2304   bool finished = false;
2305   RenderTaskFinished renderTaskFinished( finished );
2306   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2307   application.SendNotification();
2308
2309   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2310   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2311   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2312   DALI_TEST_CHECK( lastSyncObj == NULL );
2313
2314   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2315   application.SendNotification(); //         Input,    Expected  Input,    Expected
2316   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2317   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__ ) );
2318
2319   lastSyncObj = sync.GetLastSyncObject();
2320   DALI_TEST_CHECK( lastSyncObj == NULL );
2321
2322   END_TEST;
2323 }
2324
2325 int UtcDaliRenderTaskOnceNoSync05(void)
2326 {
2327   TestApplication application;
2328
2329   tet_infoline("Testing RenderTask Render Once\n"
2330                "SetRefreshRate(ONCE), resource load failed, completes render task.\n"
2331                "PRE: resources failed to load\n"
2332                "POST: No finished signal sent.");
2333
2334   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2335   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2336   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2337   drawTrace.Enable(true);
2338
2339   Actor rootActor = Actor::New();
2340   Stage::GetCurrent().Add( rootActor );
2341
2342   CameraActor offscreenCameraActor = CameraActor::New();
2343   Stage::GetCurrent().Add( offscreenCameraActor );
2344   Actor secondRootActor = CreateRenderableActorFailed(application, "aFile.jpg");
2345   Stage::GetCurrent().Add(secondRootActor);
2346
2347   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2348   bool finished = false;
2349   RenderTaskFinished renderTaskFinished( finished );
2350   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2351   application.SendNotification();
2352
2353   // START PROCESS/RENDER                    Input,     Expected  Input,    Expected
2354   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2355
2356   // CHANGE TO RENDER ONCE,
2357   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2358   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2359
2360   END_TEST;
2361 }
2362
2363
2364
2365 int UtcDaliRenderTaskOnceChain01(void)
2366 {
2367   TestApplication application;
2368
2369   tet_infoline("Testing RenderTask Render Once Chained render tasks\n"
2370                "SetRefreshRate(ONCE), resource load completes, both render tasks render.\n"
2371                "PRE: resources ready\n"
2372                "POST: 2 finished signals sent.");
2373
2374   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2375   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2376   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2377   drawTrace.Enable(true);
2378
2379   Actor defaultRootActor = Actor::New(); // Root for default RT
2380   Stage::GetCurrent().Add( defaultRootActor );
2381
2382   CameraActor offscreenCameraActor = CameraActor::New();
2383   Stage::GetCurrent().Add( offscreenCameraActor );
2384   Actor firstRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2385   Stage::GetCurrent().Add(firstRootActor);
2386
2387   // first render task
2388   RenderTask firstTask = CreateRenderTask(application, offscreenCameraActor, defaultRootActor, firstRootActor, RenderTask::REFRESH_ONCE, false);
2389   bool firstFinished = false;
2390   RenderTaskFinished renderTask1Finished( firstFinished );
2391   firstTask.FinishedSignal().Connect( &application, renderTask1Finished );
2392
2393   // Second render task
2394   FrameBufferImage fbo = firstTask.GetTargetFrameBuffer();
2395   Actor secondRootActor = CreateRenderableActor( fbo );
2396   Stage::GetCurrent().Add(secondRootActor);
2397   RenderTask secondTask = CreateRenderTask(application, offscreenCameraActor, defaultRootActor, secondRootActor, RenderTask::REFRESH_ONCE, false);
2398   bool secondFinished = false;
2399   RenderTaskFinished renderTask2Finished( secondFinished );
2400   secondTask.FinishedSignal().Connect( &application, renderTask2Finished );
2401
2402   application.SendNotification();
2403
2404   //Both render tasks are executed.
2405   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,  firstFinished, false, true, __LINE__ ) );
2406   DALI_TEST_CHECK( firstFinished == false );
2407   DALI_TEST_CHECK( secondFinished == false );
2408
2409   //Nothing else to render and both render task should have finished now
2410   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,  firstFinished, true, false, __LINE__ ) );
2411   DALI_TEST_CHECK( firstFinished == true );
2412   DALI_TEST_CHECK( secondFinished == true );
2413
2414   END_TEST;
2415 }
2416
2417 int UtcDaliRenderTaskProperties(void)
2418 {
2419   TestApplication application;
2420
2421   RenderTask task = Stage::GetCurrent().GetRenderTaskList().CreateTask();
2422
2423   Property::IndexContainer indices;
2424   task.GetPropertyIndices( indices );
2425   DALI_TEST_CHECK( indices.Size() );
2426   DALI_TEST_EQUALS( indices.Size(), task.GetPropertyCount(), TEST_LOCATION );
2427   END_TEST;
2428 }
2429
2430 int UtcDaliRenderTaskSetScreenToFrameBufferMappingActor(void)
2431 {
2432   TestApplication application;
2433   tet_infoline("Testing RenderTask::SetScreenToFrameBufferMappingActor ");
2434
2435   Stage stage = Stage::GetCurrent();
2436   Size stageSize = stage.GetSize();
2437   Actor mappingActor = Actor::New();
2438   Vector2 scale( 0.6f, 0.75f);
2439   Vector2 offset( stageSize.x*0.1f, stageSize.y*0.15f);
2440   mappingActor.SetSize( stageSize * scale );
2441   mappingActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2442   mappingActor.SetPosition( offset.x, offset.y );
2443   stage.Add( mappingActor );
2444
2445   Actor offscreenActor = Actor::New();
2446   offscreenActor.SetSize( stageSize );
2447   offscreenActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2448   stage.Add( offscreenActor );
2449
2450   RenderTaskList taskList = stage.GetRenderTaskList();
2451   RenderTask renderTask = taskList.CreateTask();
2452   FrameBufferImage frameBufferImage =  FrameBufferImage::New(stageSize.width*scale.x, stageSize.height*scale.y, Pixel::A8);
2453   renderTask.SetSourceActor( offscreenActor );
2454   renderTask.SetExclusive( true );
2455   renderTask.SetInputEnabled( true );
2456   renderTask.SetTargetFrameBuffer( frameBufferImage );
2457   renderTask.SetRefreshRate( RenderTask::REFRESH_ONCE );
2458   renderTask.SetScreenToFrameBufferMappingActor( mappingActor );
2459   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2460
2461   // Render and notify
2462   application.SendNotification();
2463   application.Render();
2464   application.Render();
2465   application.SendNotification();
2466
2467   Vector2 screenCoordinates( stageSize.x * 0.05f, stageSize.y * 0.05f );
2468   Dali::HitTestAlgorithm::Results results;
2469   DALI_TEST_CHECK( !results.actor );
2470   DALI_TEST_EQUALS( Vector2::ZERO, results.actorCoordinates, 0.1f, TEST_LOCATION );
2471   // miss expected, results not changed
2472   DALI_TEST_CHECK( false == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
2473   DALI_TEST_CHECK( !results.actor );
2474   DALI_TEST_EQUALS( Vector2::ZERO, results.actorCoordinates, 0.1f, TEST_LOCATION );
2475
2476   screenCoordinates.x = stageSize.x * 0.265f;
2477   screenCoordinates.y = stageSize.y * 0.33f;
2478   results.actor = Actor();
2479   results.actorCoordinates = Vector2::ZERO;
2480   // hit expected, results changed
2481   DALI_TEST_CHECK( true == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
2482   DALI_TEST_CHECK( results.actor  == offscreenActor );
2483   DALI_TEST_EQUALS( (screenCoordinates-offset)/scale , results.actorCoordinates, 0.1f, TEST_LOCATION );
2484
2485   screenCoordinates.x = stageSize.x * 0.435f;
2486   screenCoordinates.y = stageSize.y * 0.52f;
2487   // hit expected, results changed
2488   DALI_TEST_CHECK( true == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
2489   DALI_TEST_CHECK( results.actor  == offscreenActor );
2490   const Vector2 expectedCoordinates = (screenCoordinates-offset)/scale;
2491   DALI_TEST_EQUALS( expectedCoordinates , results.actorCoordinates, 0.1f, TEST_LOCATION );
2492
2493   screenCoordinates.x = stageSize.x * 0.65f;
2494   screenCoordinates.y = stageSize.y * 0.95f;
2495   // miss expected, results not changed
2496   DALI_TEST_CHECK( false == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
2497   DALI_TEST_CHECK( results.actor  == offscreenActor );
2498   DALI_TEST_EQUALS( expectedCoordinates , results.actorCoordinates, 0.1f, TEST_LOCATION );
2499   END_TEST;
2500 }
2501
2502 int UtcDaliRenderTaskFinishInvisibleSourceActor(void)
2503 {
2504   TestApplication application;
2505
2506   tet_infoline("Testing RenderTask::FinishInvisibleSourceActor()");
2507
2508   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2509   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2510
2511   CameraActor offscreenCameraActor = CameraActor::New();
2512
2513   Stage::GetCurrent().Add( offscreenCameraActor );
2514
2515   BufferImage image = BufferImage::New( 10, 10 );
2516   Actor rootActor = CreateRenderableActor( image );
2517   rootActor.SetSize( 10, 10 );
2518   rootActor.SetVisible(false);
2519   Stage::GetCurrent().Add( rootActor );
2520
2521   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
2522   NativeImageInterfacePtr testNativeImagePtr = TestNativeImage::New(10, 10);
2523   FrameBufferImage frameBufferImage = FrameBufferImage::New( *testNativeImagePtr.Get() );
2524
2525   // Flush all outstanding messages
2526   application.SendNotification();
2527   application.Render();
2528
2529   RenderTask newTask = taskList.CreateTask();
2530   newTask.SetCameraActor( offscreenCameraActor );
2531   newTask.SetSourceActor( rootActor );
2532   newTask.SetInputEnabled( false );
2533   newTask.SetClearColor( Vector4( 0.f, 0.f, 0.f, 0.f ) );
2534   newTask.SetClearEnabled( true );
2535   newTask.SetExclusive( true );
2536   newTask.SetRefreshRate( RenderTask::REFRESH_ONCE );
2537   newTask.SetTargetFrameBuffer( frameBufferImage );
2538   newTask.SetProperty( RenderTask::Property::REQUIRES_SYNC, true );
2539
2540   // Framebuffer doesn't actually get created until Connected, i.e. by previous line
2541
2542   bool finished = false;
2543   RenderTaskFinished renderTaskFinished( finished );
2544   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2545
2546   // Flush the queue and render.
2547   application.SendNotification();
2548
2549   // 1 render to process render task, then wait for sync before finished msg is sent
2550   // from update to the event thread.
2551
2552   application.Render();
2553   application.SendNotification();
2554   DALI_TEST_CHECK( !finished );
2555
2556   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2557   DALI_TEST_CHECK( lastSyncObj != NULL );
2558
2559   application.Render();
2560   DALI_TEST_EQUALS( (Integration::KeepUpdating::Reasons)(application.GetUpdateStatus() & Integration::KeepUpdating::RENDER_TASK_SYNC), Integration::KeepUpdating::RENDER_TASK_SYNC, TEST_LOCATION );
2561   application.SendNotification();
2562   DALI_TEST_CHECK( !finished );
2563
2564   application.Render();
2565   DALI_TEST_EQUALS( (Integration::KeepUpdating::Reasons)(application.GetUpdateStatus() & Integration::KeepUpdating::RENDER_TASK_SYNC), Integration::KeepUpdating::RENDER_TASK_SYNC, TEST_LOCATION );
2566   application.SendNotification();
2567   DALI_TEST_CHECK( ! finished );
2568
2569   sync.SetObjectSynced( lastSyncObj, true );
2570
2571   application.Render();
2572   application.SendNotification();
2573   DALI_TEST_CHECK( !finished );
2574
2575   application.Render();
2576   application.SendNotification();
2577   DALI_TEST_CHECK( finished );
2578   finished = false;
2579
2580   application.Render(); // Double check no more finished signal
2581   application.SendNotification();
2582   DALI_TEST_CHECK( ! finished );
2583
2584   END_TEST;
2585 }
2586
2587 int UtcDaliRenderTaskFinishMissingImage(void)
2588 {
2589   TestApplication application;
2590
2591   // Previously we had bugs where not having a resource ID would cause render-tasks to wait forever
2592   tet_infoline("Testing RenderTask::SignalFinished() when an Actor has no Image set");
2593
2594   Stage stage = Stage::GetCurrent();
2595
2596   BufferImage image = BufferImage::New( 10, 10 );
2597   Actor rootActor = CreateRenderableActor( image );
2598   rootActor.SetSize( 10, 10 );
2599   stage.Add( rootActor );
2600
2601   Actor actorWithMissingImage = CreateRenderableActor( Image() );
2602   actorWithMissingImage.SetSize( 10, 10 );
2603   stage.Add( actorWithMissingImage );
2604
2605   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
2606   RenderTask newTask = taskList.CreateTask();
2607   newTask.SetInputEnabled( false );
2608   newTask.SetClearColor( Vector4( 0.f, 0.f, 0.f, 0.f ) );
2609   newTask.SetClearEnabled( true );
2610   newTask.SetExclusive( true );
2611   newTask.SetRefreshRate( RenderTask::REFRESH_ONCE );
2612
2613   bool finished = false;
2614   RenderTaskFinished renderTaskFinished( finished );
2615   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2616
2617   // 1 render to process render task, then 1 before finished msg is sent from update to the event thread.
2618   application.SendNotification();
2619   application.Render();
2620   application.Render();
2621
2622   application.SendNotification();
2623   DALI_TEST_CHECK( finished );
2624
2625   END_TEST;
2626 }
2627
2628 int UtcDaliRenderTaskWorldToViewport(void)
2629 {
2630   TestApplication application( static_cast<size_t>(400), static_cast<size_t>(400) ); // square surface
2631
2632   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
2633
2634   Actor actor = Actor::New();
2635   actor.SetSize(100.0f, 100.0f);
2636   actor.SetPosition( Vector3(0.0, 0.0, 0.0) );
2637
2638   actor.SetParentOrigin( Vector3(0.5, 0.5, 0.5) );
2639   actor.SetAnchorPoint( Vector3(0.5, 0.5, 0.5) );
2640
2641   Stage::GetCurrent().Add(actor);
2642
2643   application.SendNotification();
2644   application.Render();
2645   application.SendNotification();
2646
2647   RenderTask task = taskList.GetTask( 0u );
2648
2649   CameraActor camera = task.GetCameraActor();
2650
2651   Vector2 screenSize = task.GetCurrentViewportSize();
2652
2653   float screenX = 0.0;
2654   float screenY = 0.0;
2655
2656   bool ok = task.WorldToViewport(actor.GetCurrentWorldPosition(), screenX, screenY);
2657   DALI_TEST_CHECK(ok == true);
2658
2659   DALI_TEST_EQUALS(screenX, screenSize.x/2, Math::MACHINE_EPSILON_10000, TEST_LOCATION);
2660   DALI_TEST_EQUALS(screenY, screenSize.y/2, Math::MACHINE_EPSILON_10000, TEST_LOCATION);
2661
2662   Actor actor2 = Actor::New();
2663   float actor2Size = 100.f;
2664   actor2.SetSize( actor2Size, actor2Size );
2665   actor2.SetPosition( Vector3(0.0, 0.0, 0.0) );
2666   actor2.SetParentOrigin( Vector3(0.5, 0.5, 0.0) );
2667   actor2.SetAnchorPoint( Vector3(0.5, 0.5, 0.0) );
2668   Stage::GetCurrent().Add( actor2 );
2669   actor2.Add(actor);
2670   actor.SetParentOrigin( Vector3(0,0,0) );
2671
2672   application.SendNotification();
2673   application.Render();
2674   application.SendNotification();
2675
2676   ok = task.WorldToViewport(actor.GetCurrentWorldPosition(), screenX, screenY);
2677   DALI_TEST_CHECK(ok == true);
2678
2679   DALI_TEST_EQUALS(screenX, screenSize.x/2 - actor2Size/2, Math::MACHINE_EPSILON_10000, TEST_LOCATION);
2680   DALI_TEST_EQUALS(screenY, screenSize.y/2 - actor2Size/2, Math::MACHINE_EPSILON_10000, TEST_LOCATION);
2681
2682   END_TEST;
2683 }
2684
2685
2686 int UtcDaliRenderTaskViewportToLocal(void)
2687 {
2688   TestApplication application;
2689   Actor actor = Actor::New();
2690   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2691   actor.SetSize(100.0f, 100.0f);
2692   actor.SetPosition(10.0f, 10.0f);
2693   Stage::GetCurrent().Add(actor);
2694
2695   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
2696   RenderTask task = taskList.GetTask( 0u );
2697
2698   // flush the queue and render once
2699   application.SendNotification();
2700   application.Render();
2701   application.SendNotification();
2702   application.Render();
2703
2704   float localX;
2705   float localY;
2706
2707   float rtLocalX;
2708   float rtLocalY;
2709
2710   float screenX = 50.0f;
2711   float screenY = 50.0f;
2712
2713   DALI_TEST_CHECK( actor.ScreenToLocal(localX, localY, screenX, screenY) );
2714
2715   DALI_TEST_CHECK( task.ViewportToLocal(actor, screenX, screenY, rtLocalX, rtLocalY ) );
2716
2717   DALI_TEST_EQUALS(localX, rtLocalX, 0.01f, TEST_LOCATION);
2718   DALI_TEST_EQUALS(localY, rtLocalY, 0.01f, TEST_LOCATION);
2719
2720   END_TEST;
2721
2722 }
2723
2724 int UtcDaliRenderTaskRequiresSync(void)
2725 {
2726   TestApplication application;
2727   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
2728
2729   RenderTask newTask = taskList.CreateTask();
2730   newTask.SetProperty( RenderTask::Property::REQUIRES_SYNC, false );
2731
2732   DALI_TEST_EQUALS( newTask.GetProperty< bool >( RenderTask::Property::REQUIRES_SYNC ), false, TEST_LOCATION );
2733   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< bool >( newTask, RenderTask::Property::REQUIRES_SYNC ), false, TEST_LOCATION );
2734
2735   newTask.SetProperty( RenderTask::Property::REQUIRES_SYNC, true );
2736
2737   DALI_TEST_EQUALS( newTask.GetProperty< bool >( RenderTask::Property::REQUIRES_SYNC ), true, TEST_LOCATION );
2738   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< bool >( newTask, RenderTask::Property::REQUIRES_SYNC ), true, TEST_LOCATION );
2739
2740   END_TEST;
2741 }