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