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