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