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