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