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