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