Redundant assignments and unread values.
[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     (void) 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     (void) 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     (void) 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     (void) 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     (void) 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     (void) 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
1857   DALI_TEST_EQUALS( application.GetUpdateStatus(), 0, TEST_LOCATION );
1858   END_TEST;
1859 }
1860
1861
1862 int UtcDaliRenderTaskContinuous01(void)
1863 {
1864   TestApplication application;
1865
1866   tet_infoline("Testing RenderTask Render Continuous using loading image\nPRE: render task not ready (source actor not staged)\nPOST:continuous renders, no Finished signal");
1867
1868   // SETUP AN OFFSCREEN RENDER TASK
1869   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1870   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1871   drawTrace.Enable(true);
1872
1873   Actor rootActor = Actor::New();
1874   Stage::GetCurrent().Add( rootActor );
1875
1876   CameraActor offscreenCameraActor = CameraActor::New();
1877   Stage::GetCurrent().Add( offscreenCameraActor );
1878
1879   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg");
1880   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1881   Integration::ResourceId imageRequestId = imageRequest->GetId();
1882   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1883
1884   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1885   bool finished = false;
1886   RenderTaskFinished renderTaskFinished( finished );
1887   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1888   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1889   application.SendNotification();
1890
1891   // START PROCESS/RENDER                     Input,    Expected  Input, Expected, KeepUpdating
1892   DALI_TEST_CHECK( UpdateRender(application,  drawTrace, false,   finished, false, false, __LINE__ ) );
1893   application.GetPlatform().ClearReadyResources();
1894
1895   // ADD SOURCE ACTOR TO STAGE - expect continuous renders to start, no finished signal
1896   Stage::GetCurrent().Add(secondRootActor);
1897   application.SendNotification();
1898
1899   // CONTINUE PROCESS/RENDER                  Input,    Expected  Input,    Expected
1900   DALI_TEST_CHECK( UpdateRender(application,  drawTrace, true,    finished, false, false, __LINE__ ) );
1901   END_TEST;
1902 }
1903
1904
1905 int UtcDaliRenderTaskContinuous02(void)
1906 {
1907   TestApplication application;
1908
1909   tet_infoline("Testing RenderTask Render Continuous using loading image\nPRE: render task not ready (source actor not visible)\nPOST:continuous renders, no Finished signal");
1910
1911   // SETUP AN OFFSCREEN RENDER TASK
1912   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1913   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1914   drawTrace.Enable(true);
1915
1916   Actor rootActor = Actor::New();
1917   Stage::GetCurrent().Add( rootActor );
1918
1919   CameraActor offscreenCameraActor = CameraActor::New();
1920   Stage::GetCurrent().Add( offscreenCameraActor );
1921
1922   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg");
1923   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1924   Integration::ResourceId imageRequestId = imageRequest->GetId();
1925   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1926   Stage::GetCurrent().Add(secondRootActor);
1927   secondRootActor.SetVisible(false);
1928
1929   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1930   bool finished = false;
1931   RenderTaskFinished renderTaskFinished( finished );
1932   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1933   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1934   application.SendNotification();
1935
1936   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected, KeepUpdating
1937   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, false, __LINE__ ) );
1938   application.GetPlatform().ClearReadyResources();
1939
1940   // MAKE SOURCE ACTOR VISIBLE - expect continuous renders to start, no finished signal
1941   secondRootActor.SetVisible(true);
1942   application.SendNotification();
1943
1944   // CONTINUE PROCESS/RENDER                 Input,    Expected  Input,    Expected
1945   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
1946   END_TEST;
1947 }
1948
1949 int UtcDaliRenderTaskContinuous03(void)
1950 {
1951   TestApplication application;
1952
1953   tet_infoline("Testing RenderTask Render Continuous using loading image\nPRE: render task not ready (camera actor not staged)\nPOST:continuous renders, no Finished signal");
1954
1955   // SETUP AN OFFSCREEN RENDER TASK
1956   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1957   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1958   drawTrace.Enable(true);
1959
1960   Actor rootActor = Actor::New();
1961   Stage::GetCurrent().Add( rootActor );
1962
1963   CameraActor offscreenCameraActor = CameraActor::New();
1964   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg");
1965   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1966   Integration::ResourceId imageRequestId = imageRequest->GetId();
1967   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1968   Stage::GetCurrent().Add(secondRootActor);
1969
1970   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1971   bool finished = false;
1972   RenderTaskFinished renderTaskFinished( finished );
1973   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1974   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1975   application.SendNotification();
1976
1977   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1978   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, false, __LINE__ ) );
1979   application.GetPlatform().ClearReadyResources();
1980
1981   // ADD CAMERA ACTOR TO STAGE - expect continuous renders to start, no finished signal
1982   Stage::GetCurrent().Add( offscreenCameraActor );
1983   application.SendNotification();
1984
1985   // CONTINUE PROCESS/RENDER                 Input,    Expected  Input,    Expected
1986   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
1987   END_TEST;
1988 }
1989
1990
1991 int UtcDaliRenderTaskContinuous04(void)
1992 {
1993   TestApplication application;
1994
1995   tet_infoline("Testing RenderTask Render Continuous using loading image\nPRE: Resource not ready\nPOST:continuous renders, no Finished signal");
1996
1997   // SETUP AN OFFSCREEN RENDER TASK
1998   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1999   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2000   drawTrace.Enable(true);
2001
2002   Actor rootActor = Actor::New();
2003   Stage::GetCurrent().Add( rootActor );
2004
2005   CameraActor offscreenCameraActor = CameraActor::New();
2006   Stage::GetCurrent().Add( offscreenCameraActor );
2007   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg");
2008   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2009   Integration::ResourceId imageRequestId = imageRequest->GetId();
2010   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2011   Stage::GetCurrent().Add(secondRootActor);
2012
2013   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
2014   bool finished = false;
2015   RenderTaskFinished renderTaskFinished( finished );
2016   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2017   application.SendNotification();
2018
2019   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2020   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2021   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2022
2023   // FINISH RESOURCE LOADING - expect 'continuous' renders to start, no finished signal
2024   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2025   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2026   END_TEST;
2027 }
2028
2029 int UtcDaliRenderTaskContinous05(void)
2030 {
2031   TestApplication application;
2032
2033   tet_infoline("Testing RenderTask Render Continuous using Mesh which accesses texture through sampler with loading image\n"
2034                "PRE: Resource not ready\nPOST:continuous renders, no Finished signal");
2035
2036   // SETUP AN OFFSCREEN RENDER TASK
2037   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2038   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2039   drawTrace.Enable(true);
2040
2041   Actor rootActor = Actor::New();
2042   Stage::GetCurrent().Add( rootActor );
2043
2044   CameraActor offscreenCameraActor = CameraActor::New();
2045   Stage::GetCurrent().Add( offscreenCameraActor );
2046
2047   Shader shader = CreateShader();
2048
2049
2050   Image image = CreateLoadingImage(application, "aFile.jpg");
2051   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2052   Integration::ResourceId imageRequestId = imageRequest->GetId();
2053   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2054   TextureSet textureSet = CreateTextureSet( image );
2055
2056   Geometry geometry = CreateQuadGeometry();
2057   Renderer renderer = Renderer::New(geometry, shader);
2058   renderer.SetTextures( textureSet );
2059   Actor secondRootActor = Actor::New();
2060   secondRootActor.AddRenderer(renderer);
2061   secondRootActor.SetSize(100, 100);
2062   Stage::GetCurrent().Add(secondRootActor);
2063
2064   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
2065   bool finished = false;
2066   RenderTaskFinished renderTaskFinished( finished );
2067   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2068   application.SendNotification();
2069
2070   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2071   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2072   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2073
2074   // FINISH RESOURCE LOADING - expect 'continuous' renders to start, no finished signal
2075   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2076   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2077
2078   END_TEST;
2079 }
2080
2081
2082 int UtcDaliRenderTaskOnce01(void)
2083 {
2084   TestApplication application;
2085
2086   tet_infoline("Testing RenderTask Render Once GlSync, using loading image\nPRE: Resources not ready, Source not visible\nPOST: Finished signal sent once only");
2087
2088   // SETUP AN OFFSCREEN RENDER TASK
2089   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2090   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2091   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2092   drawTrace.Enable(true);
2093
2094   Actor rootActor = Actor::New();
2095   Stage::GetCurrent().Add( rootActor );
2096
2097   CameraActor offscreenCameraActor = CameraActor::New();
2098   Stage::GetCurrent().Add( offscreenCameraActor );
2099   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg");
2100   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2101   Integration::ResourceId imageRequestId = imageRequest->GetId();
2102   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2103
2104   Stage::GetCurrent().Add(secondRootActor);
2105
2106   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, true);
2107   bool finished = false;
2108   RenderTaskFinished renderTaskFinished( finished );
2109   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2110   application.SendNotification();
2111
2112   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2113   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2114   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2115
2116   // MAKE SOURCE VISIBLE
2117   secondRootActor.SetVisible(true);
2118   application.SendNotification();
2119   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2120   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2121
2122   // FINISH RESOURCE LOADING - expect no rendering yet
2123   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2124   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2125   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2126   DALI_TEST_CHECK( lastSyncObj != NULL );
2127
2128   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2129   application.GetPlatform().ClearReadyResources();
2130   sync.SetObjectSynced( lastSyncObj, true );
2131   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,   finished, false, true, __LINE__  ) );
2132   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__  ) );
2133   END_TEST;
2134 }
2135
2136 int UtcDaliRenderTaskOnce02(void)
2137 {
2138   TestApplication application;
2139
2140   tet_infoline("Testing RenderTask Render Once GlSync, using Mesh which accesses texture through sampler with loading image.\n"
2141                "PRE: Resources not ready\nPOST: Finished signal sent once only");
2142
2143   // SETUP AN OFFSCREEN RENDER TASK
2144   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2145   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2146   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2147   drawTrace.Enable(true);
2148
2149   Actor rootActor = Actor::New();
2150   Stage::GetCurrent().Add( rootActor );
2151
2152   CameraActor offscreenCameraActor = CameraActor::New();
2153   Stage::GetCurrent().Add( offscreenCameraActor );
2154
2155   Shader shader = CreateShader();
2156   Image image = CreateLoadingImage(application, "aFile.jpg");
2157   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2158   Integration::ResourceId imageRequestId = imageRequest->GetId();
2159   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2160   TextureSet textureSet = CreateTextureSet( image );
2161
2162   Geometry geometry = CreateQuadGeometry();
2163   Renderer renderer = Renderer::New(geometry, shader);
2164   renderer.SetTextures( textureSet );
2165   Actor secondRootActor = Actor::New();
2166   secondRootActor.AddRenderer(renderer);
2167   secondRootActor.SetSize(100, 100);
2168   Stage::GetCurrent().Add(secondRootActor);
2169
2170   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, true);
2171   bool finished = false;
2172   RenderTaskFinished renderTaskFinished( finished );
2173   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2174   application.SendNotification();
2175
2176   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2177    DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2178    DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2179
2180    // FINISH RESOURCE LOADING - expect no rendering yet
2181    CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2182    DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2183    Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2184    DALI_TEST_CHECK( lastSyncObj != NULL );
2185
2186    DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2187    application.GetPlatform().ClearReadyResources();
2188    sync.SetObjectSynced( lastSyncObj, true );
2189    DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,   finished, false, true, __LINE__  ) );
2190    DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__  ) );
2191
2192    END_TEST;
2193 }
2194
2195 int UtcDaliRenderTaskOnce03(void)
2196 {
2197   TestApplication application;
2198
2199   tet_infoline("Testing RenderTask Render Once GlSync, using loading image. Switch from render always after ready to render once\n"
2200                "PRE: Render task ready, Image not loaded\n"
2201                "POST: Finished signal sent only once");
2202
2203   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2204   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2205   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2206   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2207   drawTrace.Enable(true);
2208
2209   Actor rootActor = Actor::New();
2210   Stage::GetCurrent().Add( rootActor );
2211
2212   CameraActor offscreenCameraActor = CameraActor::New();
2213   Stage::GetCurrent().Add( offscreenCameraActor );
2214   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg");
2215   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2216   Integration::ResourceId imageRequestId = imageRequest->GetId();
2217   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2218   Stage::GetCurrent().Add(secondRootActor);
2219
2220   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
2221   bool finished = false;
2222   RenderTaskFinished renderTaskFinished( finished );
2223   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2224   application.SendNotification();
2225
2226   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2227   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2228   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2229
2230   // FINISH RESOURCE LOADING
2231   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2232   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2233   application.GetPlatform().ClearReadyResources();
2234   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2235
2236   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2237   application.SendNotification(); //         Input,    Expected  Input,    Expected
2238   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2239   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2240   DALI_TEST_CHECK( lastSyncObj != NULL );
2241
2242   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
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   sync.SetObjectSynced( lastSyncObj, true );
2246   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__  ) );
2247   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__  ) );
2248
2249   END_TEST;
2250 }
2251
2252
2253 int UtcDaliRenderTaskOnce04(void)
2254 {
2255   TestApplication application;
2256   tet_infoline("Testing RenderTask Render Once GlSync, using Mesh which accesses texture through sampler with loading image.\n"
2257                "Switch from render always after ready to render once\n"
2258                "PRE: Render task ready, Image not loaded\n"
2259                "POST: Finished signal sent only once");
2260
2261   // SETUP AN OFFSCREEN RENDER TASK
2262   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2263   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2264   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2265   drawTrace.Enable(true);
2266
2267   Actor rootActor = Actor::New();
2268   Stage::GetCurrent().Add( rootActor );
2269
2270   CameraActor offscreenCameraActor = CameraActor::New();
2271   Stage::GetCurrent().Add( offscreenCameraActor );
2272
2273   Shader shader = CreateShader();
2274   Image image = CreateLoadingImage(application, "aFile.jpg");
2275   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2276   Integration::ResourceId imageRequestId = imageRequest->GetId();
2277   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2278   TextureSet textureSet = CreateTextureSet( image );
2279
2280   Geometry geometry = CreateQuadGeometry();
2281   Renderer renderer = Renderer::New(geometry, shader);
2282   renderer.SetTextures( textureSet );
2283   Actor secondRootActor = Actor::New();
2284   secondRootActor.AddRenderer(renderer);
2285   secondRootActor.SetSize(100, 100);
2286   Stage::GetCurrent().Add(secondRootActor);
2287
2288   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
2289   bool finished = false;
2290   RenderTaskFinished renderTaskFinished( finished );
2291   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2292   application.SendNotification();
2293
2294   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2295   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2296   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2297
2298   // FINISH RESOURCE LOADING
2299   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2300   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2301   application.GetPlatform().ClearReadyResources();
2302   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2303
2304   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2305   application.SendNotification(); //         Input,    Expected  Input,    Expected
2306   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2307   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2308   DALI_TEST_CHECK( lastSyncObj != NULL );
2309
2310   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
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   sync.SetObjectSynced( lastSyncObj, true );
2314   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__  ) );
2315   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__  ) );
2316
2317   END_TEST;
2318 }
2319
2320 int UtcDaliRenderTaskOnce05(void)
2321 {
2322   TestApplication application;
2323
2324   tet_infoline("Testing RenderTask Render Once GlSync\n"
2325                "Switch from Render always after ready to render once with resources unready\n"
2326                "PRE: Everything ready to render\n"
2327                "POST: Finished signal sent once");
2328
2329   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2330   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2331   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2332   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2333   drawTrace.Enable(true);
2334
2335   Actor rootActor = Actor::New();
2336   Stage::GetCurrent().Add( rootActor );
2337
2338   CameraActor offscreenCameraActor = CameraActor::New();
2339   Stage::GetCurrent().Add( offscreenCameraActor );
2340   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg");
2341   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2342   Integration::ResourceId imageRequestId = imageRequest->GetId();
2343   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2344   Stage::GetCurrent().Add(secondRootActor);
2345
2346   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
2347   bool finished = false;
2348   RenderTaskFinished renderTaskFinished( finished );
2349   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2350   application.SendNotification();
2351
2352   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2353   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2354   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2355
2356   // CHANGE TO RENDER ONCE
2357   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2358   application.SendNotification(); //         Input,    Expected  Input,    Expected
2359   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2360   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2361
2362   // FINISH RESOURCE LOADING
2363   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2364   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2365   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2366   DALI_TEST_CHECK( lastSyncObj != NULL );
2367   application.GetPlatform().ClearReadyResources();
2368
2369   sync.SetObjectSynced( lastSyncObj, true );
2370
2371   // Expect: No draw - we've just drawn our render task once, above. No finished signal -
2372   // we won't read the gl sync until the next frame. Continue rendering - we're waiting for
2373   // the sync
2374   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2375
2376   // Expect: 1 final draw - this Update doesn't update the scene, hence render instructions
2377   // from last frame but 1 are still present.
2378   // Finished signal should be true - we've just done the sync.
2379   // Should now stop rendering and updating - nothing left to do.
2380   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,   finished, true, false, __LINE__ ) );
2381
2382   END_TEST;
2383 }
2384
2385 int UtcDaliRenderTaskOnce07(void)
2386 {
2387   TestApplication application;
2388
2389   tet_infoline("Testing RenderTask Render Once GLSync\n"
2390                "Render once, Second call to SetRefreshRate(ONCE) triggers only one more finished signal\n"
2391                "PRE: Everything ready\n"
2392                "POST: exactly 1 finished signal per call to SetRefreshRate(ONCE)");
2393
2394   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2395   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2396   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2397   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2398   drawTrace.Enable(true);
2399
2400   Actor rootActor = Actor::New();
2401   Stage::GetCurrent().Add( rootActor );
2402
2403   CameraActor offscreenCameraActor = CameraActor::New();
2404   Stage::GetCurrent().Add( offscreenCameraActor );
2405   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg");
2406   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2407   Integration::ResourceId imageRequestId = imageRequest->GetId();
2408   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2409   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2410   application.Render();
2411   application.GetPlatform().ClearReadyResources();
2412
2413   Stage::GetCurrent().Add(secondRootActor);
2414
2415   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
2416   bool finished = false;
2417   RenderTaskFinished renderTaskFinished( finished );
2418   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2419   application.SendNotification();
2420
2421   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2422   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2423
2424   // CHANGE TO RENDER ONCE,
2425   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2426   application.SendNotification();
2427   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2428   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2429   DALI_TEST_CHECK( lastSyncObj != NULL );
2430
2431   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2432   sync.SetObjectSynced( lastSyncObj, true );
2433   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2434   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false, __LINE__ ) );
2435
2436   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2437   application.SendNotification();
2438   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2439   lastSyncObj = sync.GetLastSyncObject();
2440   DALI_TEST_CHECK( lastSyncObj != NULL );
2441
2442   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2443   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2444   sync.SetObjectSynced( lastSyncObj, true );
2445   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2446   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__ ) );
2447   END_TEST;
2448 }
2449
2450 int UtcDaliRenderTaskOnce08(void)
2451 {
2452   TestApplication application;
2453
2454   tet_infoline("Testing RenderTask Render Once GLSync\n"
2455                "Render once, Call to SetRefreshRate(ONCE) in Finished signal callback triggers "
2456                "another render & another finished signal\n"
2457                "PRE: Everything ready\n"
2458                "POST: exactly 1 finished signal per call to SetRefreshRate(ONCE)");
2459
2460
2461   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2462   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2463   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2464   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2465   sync.GetTrace().Enable(true);
2466   drawTrace.Enable(true);
2467
2468   Actor rootActor = Actor::New();
2469   Stage::GetCurrent().Add( rootActor );
2470
2471   CameraActor offscreenCameraActor = CameraActor::New();
2472   Stage::GetCurrent().Add( offscreenCameraActor );
2473   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg");
2474   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2475   Integration::ResourceId imageRequestId = imageRequest->GetId();
2476   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2477   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2478   application.Render();
2479   application.GetPlatform().ClearReadyResources();
2480
2481   Stage::GetCurrent().Add(secondRootActor);
2482
2483   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, /*GL-SYNC*/ true);
2484   bool finished = false;
2485
2486   ConnectionTracker connectionTracker;
2487   RenderTaskFinishedRenderAgain renderTaskFinishedRenderAgain( finished );
2488   newTask.FinishedSignal().Connect( &connectionTracker, renderTaskFinishedRenderAgain );
2489
2490   application.SendNotification();
2491
2492   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2493   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2494   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2495   DALI_TEST_CHECK( lastSyncObj == NULL );
2496   DALI_TEST_EQUALS( sync.GetTrace().CountMethod( "CreateSyncObject" ), 0, TEST_LOCATION );
2497
2498
2499   // CHANGE TO RENDER ONCE,
2500   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2501   application.SendNotification();
2502   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2503   lastSyncObj = sync.GetLastSyncObject();
2504   DALI_TEST_CHECK( lastSyncObj != NULL );
2505   DALI_TEST_EQUALS( sync.GetNumberOfSyncObjects(), 1, TEST_LOCATION );
2506   DALI_TEST_EQUALS( sync.GetTrace().CountMethod( "CreateSyncObject" ), 1, TEST_LOCATION );
2507
2508   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2509
2510
2511   DALI_TEST_EQUALS( sync.GetNumberOfSyncObjects(), 1, TEST_LOCATION );
2512   DALI_TEST_EQUALS( sync.GetTrace().CountMethod( "CreateSyncObject" ), 1, TEST_LOCATION );
2513
2514   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2515
2516   DALI_TEST_EQUALS( sync.GetNumberOfSyncObjects(), 1, TEST_LOCATION );
2517   DALI_TEST_EQUALS( sync.GetTrace().CountMethod( "CreateSyncObject" ), 1, TEST_LOCATION );
2518
2519   sync.SetObjectSynced( lastSyncObj, true );
2520   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2521   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__ ) );
2522   application.SendNotification();
2523
2524   // Expect SetRefreshRate to have been called again
2525   // Prevent next finished signal calling refresh once again
2526   RenderTaskFinished renderTaskFinished( finished );
2527   connectionTracker.DisconnectAll();
2528   newTask.FinishedSignal().Connect( &connectionTracker, renderTaskFinished );
2529   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2530   lastSyncObj = sync.GetLastSyncObject();
2531   DALI_TEST_CHECK( lastSyncObj != NULL );
2532
2533   sync.SetObjectSynced( lastSyncObj, true );
2534   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2535   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__ ) );
2536   END_TEST;
2537 }
2538
2539
2540 int UtcDaliRenderTaskOnce09(void)
2541 {
2542   TestApplication application;
2543
2544   tet_infoline("Testing RenderTask Render Once GlSync\n"
2545                "SetRefreshRate(ONCE) again before first finished signal has been sent.\n"
2546                "PRE: resources ready\n"
2547                "POST: Only 1 finished signal sent.");
2548
2549   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2550   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2551   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2552   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2553   drawTrace.Enable(true);
2554
2555   Actor rootActor = Actor::New();
2556   Stage::GetCurrent().Add( rootActor );
2557
2558   CameraActor offscreenCameraActor = CameraActor::New();
2559   Stage::GetCurrent().Add( offscreenCameraActor );
2560   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg");
2561   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2562   Integration::ResourceId imageRequestId = imageRequest->GetId();
2563   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2564   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2565   application.Render();
2566   application.GetPlatform().ClearReadyResources();
2567
2568   Stage::GetCurrent().Add(secondRootActor);
2569
2570   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
2571   bool finished = false;
2572   RenderTaskFinished renderTaskFinished( finished );
2573   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2574   application.SendNotification();
2575
2576   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2577   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2578
2579   // CHANGE TO RENDER ONCE,
2580   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2581   application.SendNotification();
2582   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2583   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2584   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2585
2586   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2587   application.SendNotification();
2588   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2589   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2590   DALI_TEST_CHECK( lastSyncObj != NULL );
2591
2592   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2593   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2594   sync.SetObjectSynced( lastSyncObj, true );
2595   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2596   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__  ) );
2597
2598   END_TEST;
2599 }
2600
2601 int UtcDaliRenderTaskOnce10(void)
2602 {
2603   TestApplication application;
2604
2605   tet_infoline("Testing RenderTask Render Once GlSync\n"
2606                "SetRefreshRate(ONCE), resource load failed completes render task.\n"
2607                "PRE: resources not ready\n"
2608                "POST: Only 1 finished signal sent.");
2609
2610   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2611   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2612   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2613   drawTrace.Enable(true);
2614
2615   Actor rootActor = Actor::New();
2616   Stage::GetCurrent().Add( rootActor );
2617
2618   CameraActor offscreenCameraActor = CameraActor::New();
2619   Stage::GetCurrent().Add( offscreenCameraActor );
2620   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg");
2621   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2622   Integration::ResourceId imageRequestId = imageRequest->GetId();
2623   Stage::GetCurrent().Add(secondRootActor);
2624
2625   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2626   bool finished = false;
2627   RenderTaskFinished renderTaskFinished( finished );
2628   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2629   application.SendNotification();
2630
2631   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2632   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2633   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2634
2635   // CHANGE TO RENDER ONCE,
2636   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2637   application.SendNotification();
2638   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
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
2642   tet_printf("  FailImageLoad\n");
2643
2644   FailImageLoad(application, imageRequestId); // Need to run Update again for this to complete
2645
2646   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) ); // nothing to draw
2647   application.SendNotification();
2648
2649   // load is now failed so there's nothing more to render in the render task
2650   // Expect finished signal, as all resources are complete
2651   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__ ) );
2652
2653   END_TEST;
2654 }
2655
2656 int UtcDaliRenderTaskOnceNoSync01(void)
2657 {
2658   TestApplication application;
2659
2660   tet_infoline("Testing RenderTask Render Once, using loading image\nPRE: Resources not ready, Source not visible\nPOST: Finished signal sent once only");
2661
2662   // SETUP AN OFFSCREEN RENDER TASK
2663   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2664   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2665   drawTrace.Enable(true);
2666
2667   Actor rootActor = Actor::New();
2668   Stage::GetCurrent().Add( rootActor );
2669
2670   CameraActor offscreenCameraActor = CameraActor::New();
2671   Stage::GetCurrent().Add( offscreenCameraActor );
2672   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg");
2673   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2674   Integration::ResourceId imageRequestId = imageRequest->GetId();
2675   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2676
2677   Stage::GetCurrent().Add(secondRootActor);
2678
2679   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, false);
2680   bool finished = false;
2681   RenderTaskFinished renderTaskFinished( finished );
2682   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2683   application.SendNotification();
2684
2685   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2686   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2687   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2688
2689   // FINISH RESOURCE LOADING - expect immediate rendering yet
2690   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2691   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2692   application.GetPlatform().ClearReadyResources();
2693   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__ ) );
2694   END_TEST;
2695 }
2696
2697 int UtcDaliRenderTaskOnceNoSync02(void)
2698 {
2699   TestApplication application;
2700
2701   tet_infoline("Testing RenderTask Render Once, using Mesh which accesses texture through sampler with loading image.\n"
2702                "PRE: Resources not ready\nPOST: Finished signal sent once only");
2703   // SETUP AN OFFSCREEN RENDER TASK
2704   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2705   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2706   drawTrace.Enable(true);
2707
2708   Actor rootActor = Actor::New();
2709   Stage::GetCurrent().Add( rootActor );
2710
2711   CameraActor offscreenCameraActor = CameraActor::New();
2712   Stage::GetCurrent().Add( offscreenCameraActor );
2713
2714   Shader shader = CreateShader();
2715   Image image = CreateLoadingImage(application, "aFile.jpg");
2716   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2717   Integration::ResourceId imageRequestId = imageRequest->GetId();
2718   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2719   TextureSet textureSet = CreateTextureSet( image );
2720
2721   Geometry geometry = CreateQuadGeometry();
2722   Renderer renderer = Renderer::New(geometry, shader);
2723   renderer.SetTextures( textureSet );
2724   Actor secondRootActor = Actor::New();
2725   secondRootActor.AddRenderer(renderer);
2726   secondRootActor.SetSize(100, 100);
2727   Stage::GetCurrent().Add(secondRootActor);
2728
2729   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, false);
2730   bool finished = false;
2731   RenderTaskFinished renderTaskFinished( finished );
2732   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2733   application.SendNotification();
2734
2735   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2736   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2737   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2738
2739   // FINISH RESOURCE LOADING - expect immediate rendering yet
2740   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2741   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2742   application.GetPlatform().ClearReadyResources();
2743   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__ ) );
2744
2745   END_TEST;
2746 }
2747
2748 int UtcDaliRenderTaskOnceNoSync03(void)
2749 {
2750   TestApplication application;
2751
2752   tet_infoline("Testing RenderTask Render Once, using loading image. Switch from render always after ready to render once\n"
2753                "PRE: Render task ready, Image not loaded\n"
2754                "POST: Finished signal sent only once");
2755
2756   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2757   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2758   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2759   drawTrace.Enable(true);
2760
2761   Actor rootActor = Actor::New();
2762   Stage::GetCurrent().Add( rootActor );
2763
2764   CameraActor offscreenCameraActor = CameraActor::New();
2765   Stage::GetCurrent().Add( offscreenCameraActor );
2766   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg");
2767   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2768   Integration::ResourceId imageRequestId = imageRequest->GetId();
2769   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2770   Stage::GetCurrent().Add(secondRootActor);
2771
2772   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2773   bool finished = false;
2774   RenderTaskFinished renderTaskFinished( finished );
2775   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2776   application.SendNotification();
2777
2778   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2779   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2780   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2781
2782   // FINISH RESOURCE LOADING
2783   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2784   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2785   application.GetPlatform().ClearReadyResources();
2786
2787   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2788   application.SendNotification(); //         Input,    Expected  Input,    Expected
2789   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2790   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__ ) );
2791   END_TEST;
2792 }
2793
2794 int UtcDaliRenderTaskOnceNoSync04(void)
2795 {
2796   TestApplication application;
2797
2798   tet_infoline("Testing RenderTask Render Once, using Mesh which accesses texture through sampler with loading image.\n"
2799                "Switch from render always after ready to render once\n"
2800                "PRE: Render task ready, Image not loaded\n"
2801                "POST: Finished signal sent only once");
2802
2803   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2804   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2805   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2806   drawTrace.Enable(true);
2807
2808   Actor rootActor = Actor::New();
2809   Stage::GetCurrent().Add( rootActor );
2810
2811   CameraActor offscreenCameraActor = CameraActor::New();
2812   Stage::GetCurrent().Add( offscreenCameraActor );
2813
2814   Shader shader = CreateShader();
2815   Image image = CreateLoadingImage(application, "aFile.jpg");
2816   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2817   Integration::ResourceId imageRequestId = imageRequest->GetId();
2818   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2819   TextureSet textureSet = CreateTextureSet( image );
2820
2821   Geometry geometry = CreateQuadGeometry();
2822   Renderer renderer = Renderer::New(geometry, shader);
2823   renderer.SetTextures( textureSet );
2824   Actor secondRootActor = Actor::New();
2825   secondRootActor.AddRenderer(renderer);
2826   secondRootActor.SetSize(100, 100);
2827   Stage::GetCurrent().Add(secondRootActor);
2828
2829
2830   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2831   bool finished = false;
2832   RenderTaskFinished renderTaskFinished( finished );
2833   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2834   application.SendNotification();
2835
2836   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2837   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2838   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2839
2840   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2841   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2842   DALI_TEST_CHECK( lastSyncObj == NULL );
2843
2844   // FINISH RESOURCE LOADING
2845   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2846   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2847   application.GetPlatform().ClearReadyResources();
2848
2849   lastSyncObj = sync.GetLastSyncObject();
2850   DALI_TEST_CHECK( lastSyncObj == NULL );
2851
2852   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2853   application.SendNotification(); //         Input,    Expected  Input,    Expected
2854   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2855   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__ ) );
2856
2857   lastSyncObj = sync.GetLastSyncObject();
2858   DALI_TEST_CHECK( lastSyncObj == NULL );
2859
2860   END_TEST;
2861 }
2862
2863 int UtcDaliRenderTaskOnceNoSync05(void)
2864 {
2865   TestApplication application;
2866
2867   tet_infoline("Testing RenderTask Render Once\n"
2868                "Switch from Render always after ready to render once with resources unready\n"
2869                "PRE: Everything ready to render\n"
2870                "POST: Finished signal sent once");
2871
2872   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2873   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2874   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2875   drawTrace.Enable(true);
2876
2877   Actor rootActor = Actor::New();
2878   Stage::GetCurrent().Add( rootActor );
2879
2880   CameraActor offscreenCameraActor = CameraActor::New();
2881   Stage::GetCurrent().Add( offscreenCameraActor );
2882   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg");
2883   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2884   Integration::ResourceId imageRequestId = imageRequest->GetId();
2885   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2886   Stage::GetCurrent().Add(secondRootActor);
2887
2888   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2889   bool finished = false;
2890   RenderTaskFinished renderTaskFinished( finished );
2891   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2892   application.SendNotification();
2893
2894   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2895   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2896   DALI_TEST_CHECK( lastSyncObj == NULL );
2897
2898   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2899   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2900   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2901
2902   // CHANGE TO RENDER ONCE
2903   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2904   application.SendNotification(); //         Input,    Expected  Input,    Expected
2905   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2906   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2907
2908   // FINISH RESOURCE LOADING
2909   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2910   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2911   application.GetPlatform().ClearReadyResources();
2912   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__ ) );
2913   END_TEST;
2914 }
2915
2916 int UtcDaliRenderTaskOnceNoSync07(void)
2917 {
2918   TestApplication application;
2919
2920   tet_infoline("Testing RenderTask Render Once\n"
2921                "Render once, Second call to SetRefreshRate(ONCE) triggers only one more finished signal\n"
2922                "PRE: Everything ready\n"
2923                "POST: exactly 1 finished signal per call to SetRefreshRate(ONCE)");
2924
2925   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2926   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2927   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2928   drawTrace.Enable(true);
2929
2930   Actor rootActor = Actor::New();
2931   Stage::GetCurrent().Add( rootActor );
2932
2933   CameraActor offscreenCameraActor = CameraActor::New();
2934   Stage::GetCurrent().Add( offscreenCameraActor );
2935   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg");
2936   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2937   Integration::ResourceId imageRequestId = imageRequest->GetId();
2938   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2939   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2940   application.Render();
2941   application.GetPlatform().ClearReadyResources();
2942
2943   Stage::GetCurrent().Add(secondRootActor);
2944
2945   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2946   bool finished = false;
2947   RenderTaskFinished renderTaskFinished( finished );
2948   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2949   application.SendNotification();
2950
2951   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2952   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2953
2954   // CHANGE TO RENDER ONCE,
2955   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2956   application.SendNotification();
2957   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2958   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false, __LINE__ ) );
2959
2960   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2961   application.SendNotification();
2962   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2963   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false, __LINE__ ) );
2964   END_TEST;
2965 }
2966
2967 int UtcDaliRenderTaskOnceNoSync08(void)
2968 {
2969   TestApplication application;
2970
2971   tet_infoline("Testing RenderTask Render Once\n"
2972                "Render once, Call to SetRefreshRate(ONCE) in Finished signal callback triggers\n"
2973                "another render & another finished signal\n"
2974                "PRE: Everything ready\n"
2975                "POST: exactly 1 finished signal per call to SetRefreshRate(ONCE)");
2976
2977
2978   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2979   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2980   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2981   drawTrace.Enable(true);
2982
2983   Actor rootActor = Actor::New();
2984   Stage::GetCurrent().Add( rootActor );
2985
2986   CameraActor offscreenCameraActor = CameraActor::New();
2987   Stage::GetCurrent().Add( offscreenCameraActor );
2988   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg");
2989   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2990   Integration::ResourceId imageRequestId = imageRequest->GetId();
2991   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2992   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2993   application.Render();
2994   application.GetPlatform().ClearReadyResources();
2995
2996   Stage::GetCurrent().Add(secondRootActor);
2997
2998   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2999   bool finished = false;
3000
3001   ConnectionTracker connectionTracker;
3002   RenderTaskFinishedRenderAgain renderTaskFinishedRenderAgain( finished );
3003   newTask.FinishedSignal().Connect( &connectionTracker, renderTaskFinishedRenderAgain );
3004
3005   application.SendNotification();
3006
3007   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
3008   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
3009
3010   // CHANGE TO RENDER ONCE,
3011   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
3012   application.SendNotification();
3013   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
3014   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false, __LINE__ ) );
3015
3016   // Expect SetRefreshRate to have been called again
3017   // Prevent next finished signal calling refresh once again
3018   RenderTaskFinished renderTaskFinished( finished );
3019   connectionTracker.DisconnectAll();
3020   newTask.FinishedSignal().Connect( &connectionTracker, renderTaskFinished );
3021
3022   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
3023   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false, __LINE__ ) );
3024   END_TEST;
3025 }
3026
3027
3028 int UtcDaliRenderTaskOnceNoSync09(void)
3029 {
3030   TestApplication application;
3031
3032   tet_infoline("Testing RenderTask Render Once\n"
3033                "SetRefreshRate(ONCE) again before first finished signal has been sent.\n"
3034                "PRE: resources ready\n"
3035                "POST: Only 1 finished signal sent.");
3036
3037   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
3038   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
3039   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
3040   drawTrace.Enable(true);
3041
3042   Actor rootActor = Actor::New();
3043   Stage::GetCurrent().Add( rootActor );
3044
3045   CameraActor offscreenCameraActor = CameraActor::New();
3046   Stage::GetCurrent().Add( offscreenCameraActor );
3047   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg");
3048   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
3049   Integration::ResourceId imageRequestId = imageRequest->GetId();
3050   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
3051   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
3052   application.Render();
3053   application.GetPlatform().ClearReadyResources();
3054
3055   Stage::GetCurrent().Add(secondRootActor);
3056
3057   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
3058   bool finished = false;
3059   RenderTaskFinished renderTaskFinished( finished );
3060   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
3061   application.SendNotification();
3062
3063   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
3064   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
3065
3066   // CHANGE TO RENDER ONCE,
3067   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
3068   application.SendNotification();
3069   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
3070   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false, __LINE__ ) );
3071
3072   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
3073   application.SendNotification();
3074   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
3075   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false, __LINE__ ) );
3076   END_TEST;
3077 }
3078
3079 int UtcDaliRenderTaskOnceNoSync10(void)
3080 {
3081   TestApplication application;
3082
3083   tet_infoline("Testing RenderTask Render Once\n"
3084                "SetRefreshRate(ONCE), resource load failed, completes render task.\n"
3085                "PRE: resources not ready\n"
3086                "POST: Only 1 finished signal sent.");
3087
3088   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
3089   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
3090   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
3091   drawTrace.Enable(true);
3092
3093   Actor rootActor = Actor::New();
3094   Stage::GetCurrent().Add( rootActor );
3095
3096   CameraActor offscreenCameraActor = CameraActor::New();
3097   Stage::GetCurrent().Add( offscreenCameraActor );
3098   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg");
3099   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
3100   Integration::ResourceId imageRequestId = imageRequest->GetId();
3101   Stage::GetCurrent().Add(secondRootActor);
3102
3103   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
3104   bool finished = false;
3105   RenderTaskFinished renderTaskFinished( finished );
3106   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
3107   application.SendNotification();
3108
3109   // START PROCESS/RENDER                    Input,     Expected  Input,    Expected
3110   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
3111   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
3112
3113   // CHANGE TO RENDER ONCE,
3114   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
3115   application.SendNotification();
3116   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
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
3120   FailImageLoad(application, imageRequestId); // Need to run Update again for this to complete
3121   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) ); // nothing to draw
3122   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, true,  false, __LINE__ ) );
3123
3124   END_TEST;
3125 }
3126
3127
3128
3129 int UtcDaliRenderTaskOnceChain01(void)
3130 {
3131   TestApplication application;
3132
3133   tet_infoline("Testing RenderTask Render Once Chained render tasks\n"
3134                "SetRefreshRate(ONCE), resource load completes, both render tasks render.\n"
3135                "PRE: resources not ready\n"
3136                "POST: 2 finished signals sent.");
3137
3138   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
3139   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
3140   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
3141   drawTrace.Enable(true);
3142
3143   Actor defaultRootActor = Actor::New(); // Root for default RT
3144   Stage::GetCurrent().Add( defaultRootActor );
3145
3146   CameraActor offscreenCameraActor = CameraActor::New();
3147   Stage::GetCurrent().Add( offscreenCameraActor );
3148   Actor firstRootActor = CreateLoadingActor(application, "aFile.jpg");
3149   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
3150   Integration::ResourceId imageRequestId = imageRequest->GetId();
3151   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
3152   Stage::GetCurrent().Add(firstRootActor);
3153
3154   // first render task
3155   RenderTask firstTask = CreateRenderTask(application, offscreenCameraActor, defaultRootActor, firstRootActor, RenderTask::REFRESH_ONCE, false);
3156   bool firstFinished = false;
3157   RenderTaskFinished renderTask1Finished( firstFinished );
3158   firstTask.FinishedSignal().Connect( &application, renderTask1Finished );
3159
3160   // Second render task
3161   FrameBufferImage fbo = firstTask.GetTargetFrameBuffer();
3162   Actor secondRootActor = CreateRenderableActor( fbo );
3163   Stage::GetCurrent().Add(secondRootActor);
3164   RenderTask secondTask = CreateRenderTask(application, offscreenCameraActor, defaultRootActor, secondRootActor, RenderTask::REFRESH_ONCE, false);
3165   bool secondFinished = false;
3166   RenderTaskFinished renderTask2Finished( secondFinished );
3167   secondTask.FinishedSignal().Connect( &application, renderTask2Finished );
3168
3169   application.SendNotification();
3170
3171   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
3172   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,  firstFinished, false, true, __LINE__ ) );
3173   DALI_TEST_CHECK( firstFinished == false );
3174   DALI_TEST_CHECK( secondFinished == false );
3175   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,  firstFinished, false, true, __LINE__ ) );
3176   DALI_TEST_CHECK( firstFinished == false );
3177   DALI_TEST_CHECK( secondFinished == false );
3178
3179   CompleteImageLoad(application, imageRequestId, imageType);
3180   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,  firstFinished, false, true, __LINE__ ) );
3181   DALI_TEST_CHECK( firstFinished == false );
3182   DALI_TEST_CHECK( secondFinished == false );
3183
3184   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,  firstFinished, true, true, __LINE__ ) );
3185   DALI_TEST_CHECK( firstFinished == true );
3186   DALI_TEST_CHECK( secondFinished == false );
3187
3188   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,  secondFinished, true, false, __LINE__ ) );
3189   DALI_TEST_CHECK( secondFinished == true );
3190
3191   END_TEST;
3192 }
3193
3194 int UtcDaliRenderTaskProperties(void)
3195 {
3196   TestApplication application;
3197
3198   RenderTask task = Stage::GetCurrent().GetRenderTaskList().CreateTask();
3199
3200   Property::IndexContainer indices;
3201   task.GetPropertyIndices( indices );
3202   DALI_TEST_CHECK( indices.Size() );
3203   DALI_TEST_EQUALS( indices.Size(), task.GetPropertyCount(), TEST_LOCATION );
3204   END_TEST;
3205 }
3206
3207 int UtcDaliRenderTaskSetScreenToFrameBufferMappingActor(void)
3208 {
3209   TestApplication application;
3210   tet_infoline("Testing RenderTask::SetScreenToFrameBufferMappingActor ");
3211
3212   Stage stage = Stage::GetCurrent();
3213   Size stageSize = stage.GetSize();
3214   Actor mappingActor = Actor::New();
3215   Vector2 scale( 0.6f, 0.75f);
3216   Vector2 offset( stageSize.x*0.1f, stageSize.y*0.15f);
3217   mappingActor.SetSize( stageSize * scale );
3218   mappingActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
3219   mappingActor.SetPosition( offset.x, offset.y );
3220   stage.Add( mappingActor );
3221
3222   Actor offscreenActor = Actor::New();
3223   offscreenActor.SetSize( stageSize );
3224   offscreenActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
3225   stage.Add( offscreenActor );
3226
3227   RenderTaskList taskList = stage.GetRenderTaskList();
3228   RenderTask renderTask = taskList.CreateTask();
3229   FrameBufferImage frameBufferImage =  FrameBufferImage::New(stageSize.width*scale.x, stageSize.height*scale.y, Pixel::A8);
3230   renderTask.SetSourceActor( offscreenActor );
3231   renderTask.SetExclusive( true );
3232   renderTask.SetInputEnabled( true );
3233   renderTask.SetTargetFrameBuffer( frameBufferImage );
3234   renderTask.SetRefreshRate( RenderTask::REFRESH_ONCE );
3235   renderTask.SetScreenToFrameBufferMappingActor( mappingActor );
3236   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
3237
3238   // Render and notify
3239   application.SendNotification();
3240   application.Render();
3241   application.Render();
3242   application.SendNotification();
3243
3244   Vector2 screenCoordinates( stageSize.x * 0.05f, stageSize.y * 0.05f );
3245   Dali::HitTestAlgorithm::Results results;
3246   DALI_TEST_CHECK( !results.actor );
3247   DALI_TEST_EQUALS( Vector2::ZERO, results.actorCoordinates, 0.1f, TEST_LOCATION );
3248   // miss expected, results not changed
3249   DALI_TEST_CHECK( false == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
3250   DALI_TEST_CHECK( !results.actor );
3251   DALI_TEST_EQUALS( Vector2::ZERO, results.actorCoordinates, 0.1f, TEST_LOCATION );
3252
3253   screenCoordinates.x = stageSize.x * 0.265f;
3254   screenCoordinates.y = stageSize.y * 0.33f;
3255   results.actor = Actor();
3256   results.actorCoordinates = Vector2::ZERO;
3257   // hit expected, results changed
3258   DALI_TEST_CHECK( true == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
3259   DALI_TEST_CHECK( results.actor  == offscreenActor );
3260   DALI_TEST_EQUALS( (screenCoordinates-offset)/scale , results.actorCoordinates, 0.1f, TEST_LOCATION );
3261
3262   screenCoordinates.x = stageSize.x * 0.435f;
3263   screenCoordinates.y = stageSize.y * 0.52f;
3264   // hit expected, results changed
3265   DALI_TEST_CHECK( true == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
3266   DALI_TEST_CHECK( results.actor  == offscreenActor );
3267   const Vector2 expectedCoordinates = (screenCoordinates-offset)/scale;
3268   DALI_TEST_EQUALS( expectedCoordinates , results.actorCoordinates, 0.1f, TEST_LOCATION );
3269
3270   screenCoordinates.x = stageSize.x * 0.65f;
3271   screenCoordinates.y = stageSize.y * 0.95f;
3272   // miss expected, results not changed
3273   DALI_TEST_CHECK( false == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
3274   DALI_TEST_CHECK( results.actor  == offscreenActor );
3275   DALI_TEST_EQUALS( expectedCoordinates , results.actorCoordinates, 0.1f, TEST_LOCATION );
3276   END_TEST;
3277 }
3278
3279 int UtcDaliRenderTaskFinishInvisibleSourceActor(void)
3280 {
3281   TestApplication application;
3282
3283   tet_infoline("Testing RenderTask::FinishInvisibleSourceActor()");
3284
3285   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
3286   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
3287
3288   CameraActor offscreenCameraActor = CameraActor::New();
3289
3290   Stage::GetCurrent().Add( offscreenCameraActor );
3291
3292   BufferImage image = BufferImage::New( 10, 10 );
3293   Actor rootActor = CreateRenderableActor( image );
3294   rootActor.SetSize( 10, 10 );
3295   rootActor.SetVisible(false);
3296   Stage::GetCurrent().Add( rootActor );
3297
3298   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
3299   NativeImageInterfacePtr testNativeImagePtr = TestNativeImage::New(10, 10);
3300   FrameBufferImage frameBufferImage = FrameBufferImage::New( *testNativeImagePtr.Get() );
3301
3302   // Flush all outstanding messages
3303   application.SendNotification();
3304   application.Render();
3305
3306   RenderTask newTask = taskList.CreateTask();
3307   newTask.SetCameraActor( offscreenCameraActor );
3308   newTask.SetSourceActor( rootActor );
3309   newTask.SetInputEnabled( false );
3310   newTask.SetClearColor( Vector4( 0.f, 0.f, 0.f, 0.f ) );
3311   newTask.SetClearEnabled( true );
3312   newTask.SetExclusive( true );
3313   newTask.SetRefreshRate( RenderTask::REFRESH_ONCE );
3314   newTask.SetTargetFrameBuffer( frameBufferImage );
3315   newTask.SetProperty( RenderTask::Property::REQUIRES_SYNC, true );
3316
3317   // Framebuffer doesn't actually get created until Connected, i.e. by previous line
3318
3319   bool finished = false;
3320   RenderTaskFinished renderTaskFinished( finished );
3321   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
3322
3323   // Flush the queue and render.
3324   application.SendNotification();
3325
3326   // 1 render to process render task, then wait for sync before finished msg is sent
3327   // from update to the event thread.
3328
3329   application.Render();
3330   application.SendNotification();
3331   DALI_TEST_CHECK( !finished );
3332
3333   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
3334   DALI_TEST_CHECK( lastSyncObj != NULL );
3335
3336   application.Render();
3337   DALI_TEST_EQUALS( (Integration::KeepUpdating::Reasons)(application.GetUpdateStatus() & Integration::KeepUpdating::RENDER_TASK_SYNC), Integration::KeepUpdating::RENDER_TASK_SYNC, TEST_LOCATION );
3338   application.SendNotification();
3339   DALI_TEST_CHECK( !finished );
3340
3341   application.Render();
3342   DALI_TEST_EQUALS( (Integration::KeepUpdating::Reasons)(application.GetUpdateStatus() & Integration::KeepUpdating::RENDER_TASK_SYNC), Integration::KeepUpdating::RENDER_TASK_SYNC, TEST_LOCATION );
3343   application.SendNotification();
3344   DALI_TEST_CHECK( ! finished );
3345
3346   sync.SetObjectSynced( lastSyncObj, true );
3347
3348   application.Render();
3349   application.SendNotification();
3350   DALI_TEST_CHECK( !finished );
3351
3352   application.Render();
3353   application.SendNotification();
3354   DALI_TEST_CHECK( finished );
3355   finished = false;
3356
3357   application.Render(); // Double check no more finished signal
3358   application.SendNotification();
3359   DALI_TEST_CHECK( ! finished );
3360
3361   END_TEST;
3362 }
3363
3364 int UtcDaliRenderTaskFinishMissingImage(void)
3365 {
3366   TestApplication application;
3367
3368   // Previously we had bugs where not having a resource ID would cause render-tasks to wait forever
3369   tet_infoline("Testing RenderTask::SignalFinished() when an Actor has no Image set");
3370
3371   Stage stage = Stage::GetCurrent();
3372
3373   BufferImage image = BufferImage::New( 10, 10 );
3374   Actor rootActor = CreateRenderableActor( image );
3375   rootActor.SetSize( 10, 10 );
3376   stage.Add( rootActor );
3377
3378   Actor actorWithMissingImage = CreateRenderableActor( Image() );
3379   actorWithMissingImage.SetSize( 10, 10 );
3380   stage.Add( actorWithMissingImage );
3381
3382   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
3383   RenderTask newTask = taskList.CreateTask();
3384   newTask.SetInputEnabled( false );
3385   newTask.SetClearColor( Vector4( 0.f, 0.f, 0.f, 0.f ) );
3386   newTask.SetClearEnabled( true );
3387   newTask.SetExclusive( true );
3388   newTask.SetRefreshRate( RenderTask::REFRESH_ONCE );
3389
3390   bool finished = false;
3391   RenderTaskFinished renderTaskFinished( finished );
3392   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
3393
3394   // 1 render to process render task, then 1 before finished msg is sent from update to the event thread.
3395   application.SendNotification();
3396   application.Render();
3397   application.Render();
3398
3399   application.SendNotification();
3400   DALI_TEST_CHECK( finished );
3401
3402   END_TEST;
3403 }
3404
3405 int UtcDaliRenderTaskWorldToViewport(void)
3406 {
3407   TestApplication application( static_cast<size_t>(400), static_cast<size_t>(400) ); // square surface
3408
3409   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
3410
3411   Actor actor = Actor::New();
3412   actor.SetSize(100.0f, 100.0f);
3413   actor.SetPosition( Vector3(0.0, 0.0, 0.0) );
3414
3415   actor.SetParentOrigin( Vector3(0.5, 0.5, 0.5) );
3416   actor.SetAnchorPoint( Vector3(0.5, 0.5, 0.5) );
3417
3418   Stage::GetCurrent().Add(actor);
3419
3420   application.SendNotification();
3421   application.Render();
3422   application.SendNotification();
3423
3424   RenderTask task = taskList.GetTask( 0u );
3425
3426   CameraActor camera = task.GetCameraActor();
3427
3428   Vector2 screenSize = task.GetCurrentViewportSize();
3429
3430   float screenX = 0.0;
3431   float screenY = 0.0;
3432
3433   bool ok = task.WorldToViewport(actor.GetCurrentWorldPosition(), screenX, screenY);
3434   DALI_TEST_CHECK(ok == true);
3435
3436   DALI_TEST_EQUALS(screenX, screenSize.x/2, Math::MACHINE_EPSILON_10000, TEST_LOCATION);
3437   DALI_TEST_EQUALS(screenY, screenSize.y/2, Math::MACHINE_EPSILON_10000, TEST_LOCATION);
3438
3439   Actor actor2 = Actor::New();
3440   float actor2Size = 100.f;
3441   actor2.SetSize( actor2Size, actor2Size );
3442   actor2.SetPosition( Vector3(0.0, 0.0, 0.0) );
3443   actor2.SetParentOrigin( Vector3(0.5, 0.5, 0.0) );
3444   actor2.SetAnchorPoint( Vector3(0.5, 0.5, 0.0) );
3445   Stage::GetCurrent().Add( actor2 );
3446   actor2.Add(actor);
3447   actor.SetParentOrigin( Vector3(0,0,0) );
3448
3449   application.SendNotification();
3450   application.Render();
3451   application.SendNotification();
3452
3453   ok = task.WorldToViewport(actor.GetCurrentWorldPosition(), screenX, screenY);
3454   DALI_TEST_CHECK(ok == true);
3455
3456   DALI_TEST_EQUALS(screenX, screenSize.x/2 - actor2Size/2, Math::MACHINE_EPSILON_10000, TEST_LOCATION);
3457   DALI_TEST_EQUALS(screenY, screenSize.y/2 - actor2Size/2, Math::MACHINE_EPSILON_10000, TEST_LOCATION);
3458
3459   END_TEST;
3460 }
3461
3462
3463 int UtcDaliRenderTaskViewportToLocal(void)
3464 {
3465   TestApplication application;
3466   Actor actor = Actor::New();
3467   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
3468   actor.SetSize(100.0f, 100.0f);
3469   actor.SetPosition(10.0f, 10.0f);
3470   Stage::GetCurrent().Add(actor);
3471
3472   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
3473   RenderTask task = taskList.GetTask( 0u );
3474
3475   // flush the queue and render once
3476   application.SendNotification();
3477   application.Render();
3478   application.SendNotification();
3479   application.Render();
3480
3481   float localX;
3482   float localY;
3483
3484   float rtLocalX;
3485   float rtLocalY;
3486
3487   float screenX = 50.0f;
3488   float screenY = 50.0f;
3489
3490   DALI_TEST_CHECK( actor.ScreenToLocal(localX, localY, screenX, screenY) );
3491
3492   DALI_TEST_CHECK( task.ViewportToLocal(actor, screenX, screenY, rtLocalX, rtLocalY ) );
3493
3494   DALI_TEST_EQUALS(localX, rtLocalX, 0.01f, TEST_LOCATION);
3495   DALI_TEST_EQUALS(localY, rtLocalY, 0.01f, TEST_LOCATION);
3496
3497   END_TEST;
3498
3499 }