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