Use Geometry::QUAD() in UTC
[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 Actor CreateLoadingActor(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   Actor actor = CreateRenderableActor(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   Actor newActor = CreateRenderableActor( 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   Actor newActor = CreateRenderableActor( 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   Actor newActor = CreateRenderableActor( 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   Actor newActor = CreateRenderableActor( 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 actors
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   Actor actor1 = CreateRenderableActor( 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   Actor actor2 = CreateRenderableActor( 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   Actor actor3 = CreateRenderableActor( 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   Actor actor1 = CreateRenderableActor( 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("DrawArrays"), 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("DrawArrays"), 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   Actor rootActor = CreateRenderableActor( 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   Actor secondRootActor = CreateLoadingActor(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   Actor secondRootActor = CreateLoadingActor(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   Actor secondRootActor = CreateLoadingActor(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   Actor secondRootActor = CreateLoadingActor(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   Shader shader = CreateShader();
1995
1996
1997   Image image = CreateLoadingImage(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED);
1998   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1999   Integration::ResourceId imageRequestId = imageRequest->GetId();
2000   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2001   TextureSet textureSet = CreateTextureSet( image );
2002
2003   Geometry geometry = Geometry::QUAD();
2004   Renderer renderer = Renderer::New(geometry, shader);
2005   renderer.SetTextures( textureSet );
2006   Actor secondRootActor = Actor::New();
2007   secondRootActor.AddRenderer(renderer);
2008   secondRootActor.SetSize(100, 100);
2009   Stage::GetCurrent().Add(secondRootActor);
2010
2011   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
2012   bool finished = false;
2013   RenderTaskFinished renderTaskFinished( finished );
2014   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2015   application.SendNotification();
2016
2017   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2018   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2019   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2020
2021   // FINISH RESOURCE LOADING - expect 'continuous' renders to start, no finished signal
2022   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2023   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2024
2025   END_TEST;
2026 }
2027
2028
2029 int UtcDaliRenderTaskOnce01(void)
2030 {
2031   TestApplication application;
2032
2033   tet_infoline("Testing RenderTask Render Once GlSync, using loading image\nPRE: Resources not ready, Source not visible\nPOST: Finished signal sent once only");
2034
2035   // SETUP AN OFFSCREEN RENDER TASK
2036   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2037   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2038   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2039   drawTrace.Enable(true);
2040
2041   Actor rootActor = Actor::New();
2042   Stage::GetCurrent().Add( rootActor );
2043
2044   CameraActor offscreenCameraActor = CameraActor::New();
2045   Stage::GetCurrent().Add( offscreenCameraActor );
2046   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED);
2047   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2048   Integration::ResourceId imageRequestId = imageRequest->GetId();
2049   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2050
2051   Stage::GetCurrent().Add(secondRootActor);
2052
2053   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, true);
2054   bool finished = false;
2055   RenderTaskFinished renderTaskFinished( finished );
2056   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2057   application.SendNotification();
2058
2059   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2060   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2061   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2062
2063   // MAKE SOURCE VISIBLE
2064   secondRootActor.SetVisible(true);
2065   application.SendNotification();
2066   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2067   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2068
2069   // FINISH RESOURCE LOADING - expect no rendering yet
2070   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2071   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2072   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2073   DALI_TEST_CHECK( lastSyncObj != NULL );
2074
2075   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2076   application.GetPlatform().ClearReadyResources();
2077   sync.SetObjectSynced( lastSyncObj, true );
2078   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,   finished, false, true, __LINE__  ) );
2079   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__  ) );
2080   END_TEST;
2081 }
2082
2083 int UtcDaliRenderTaskOnce02(void)
2084 {
2085   TestApplication application;
2086
2087   tet_infoline("Testing RenderTask Render Once GlSync, using Mesh which accesses texture through sampler with loading image.\n"
2088                "PRE: Resources not ready\nPOST: Finished signal sent once only");
2089
2090   // SETUP AN OFFSCREEN RENDER TASK
2091   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2092   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2093   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2094   drawTrace.Enable(true);
2095
2096   Actor rootActor = Actor::New();
2097   Stage::GetCurrent().Add( rootActor );
2098
2099   CameraActor offscreenCameraActor = CameraActor::New();
2100   Stage::GetCurrent().Add( offscreenCameraActor );
2101
2102   Shader shader = CreateShader();
2103   Image image = CreateLoadingImage(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED);
2104   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2105   Integration::ResourceId imageRequestId = imageRequest->GetId();
2106   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2107   TextureSet textureSet = CreateTextureSet( image );
2108
2109   Geometry geometry = Geometry::QUAD();
2110   Renderer renderer = Renderer::New(geometry, shader);
2111   renderer.SetTextures( textureSet );
2112   Actor secondRootActor = Actor::New();
2113   secondRootActor.AddRenderer(renderer);
2114   secondRootActor.SetSize(100, 100);
2115   Stage::GetCurrent().Add(secondRootActor);
2116
2117   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, true);
2118   bool finished = false;
2119   RenderTaskFinished renderTaskFinished( finished );
2120   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2121   application.SendNotification();
2122
2123   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2124    DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2125    DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2126
2127    // FINISH RESOURCE LOADING - expect no rendering yet
2128    CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2129    DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2130    Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2131    DALI_TEST_CHECK( lastSyncObj != NULL );
2132
2133    DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2134    application.GetPlatform().ClearReadyResources();
2135    sync.SetObjectSynced( lastSyncObj, true );
2136    DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,   finished, false, true, __LINE__  ) );
2137    DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__  ) );
2138
2139    END_TEST;
2140 }
2141
2142 int UtcDaliRenderTaskOnce03(void)
2143 {
2144   TestApplication application;
2145
2146   tet_infoline("Testing RenderTask Render Once GlSync, using loading image. Switch from render always after ready to render once\n"
2147                "PRE: Render task ready, Image not loaded\n"
2148                "POST: Finished signal sent only once");
2149
2150   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2151   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2152   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2153   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2154   drawTrace.Enable(true);
2155
2156   Actor rootActor = Actor::New();
2157   Stage::GetCurrent().Add( rootActor );
2158
2159   CameraActor offscreenCameraActor = CameraActor::New();
2160   Stage::GetCurrent().Add( offscreenCameraActor );
2161   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED);
2162   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2163   Integration::ResourceId imageRequestId = imageRequest->GetId();
2164   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2165   Stage::GetCurrent().Add(secondRootActor);
2166
2167   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
2168   bool finished = false;
2169   RenderTaskFinished renderTaskFinished( finished );
2170   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2171   application.SendNotification();
2172
2173   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2174   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2175   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2176
2177   // FINISH RESOURCE LOADING
2178   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2179   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2180   application.GetPlatform().ClearReadyResources();
2181   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2182
2183   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2184   application.SendNotification(); //         Input,    Expected  Input,    Expected
2185   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2186   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2187   DALI_TEST_CHECK( lastSyncObj != NULL );
2188
2189   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2190   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2191   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2192   sync.SetObjectSynced( lastSyncObj, true );
2193   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__  ) );
2194   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__  ) );
2195
2196   END_TEST;
2197 }
2198
2199
2200 int UtcDaliRenderTaskOnce04(void)
2201 {
2202   TestApplication application;
2203   tet_infoline("Testing RenderTask Render Once GlSync, using Mesh which accesses texture through sampler with loading image.\n"
2204                "Switch from render always after ready to render once\n"
2205                "PRE: Render task ready, Image not loaded\n"
2206                "POST: Finished signal sent only once");
2207
2208   // SETUP AN OFFSCREEN RENDER TASK
2209   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2210   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2211   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2212   drawTrace.Enable(true);
2213
2214   Actor rootActor = Actor::New();
2215   Stage::GetCurrent().Add( rootActor );
2216
2217   CameraActor offscreenCameraActor = CameraActor::New();
2218   Stage::GetCurrent().Add( offscreenCameraActor );
2219
2220   Shader shader = CreateShader();
2221   Image image = CreateLoadingImage(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED);
2222   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2223   Integration::ResourceId imageRequestId = imageRequest->GetId();
2224   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2225   TextureSet textureSet = CreateTextureSet( image );
2226
2227   Geometry geometry = Geometry::QUAD();
2228   Renderer renderer = Renderer::New(geometry, shader);
2229   renderer.SetTextures( textureSet );
2230   Actor secondRootActor = Actor::New();
2231   secondRootActor.AddRenderer(renderer);
2232   secondRootActor.SetSize(100, 100);
2233   Stage::GetCurrent().Add(secondRootActor);
2234
2235   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
2236   bool finished = false;
2237   RenderTaskFinished renderTaskFinished( finished );
2238   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2239   application.SendNotification();
2240
2241   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2242   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2243   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2244
2245   // FINISH RESOURCE LOADING
2246   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2247   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2248   application.GetPlatform().ClearReadyResources();
2249   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2250
2251   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2252   application.SendNotification(); //         Input,    Expected  Input,    Expected
2253   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2254   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2255   DALI_TEST_CHECK( lastSyncObj != NULL );
2256
2257   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2258   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2259   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2260   sync.SetObjectSynced( lastSyncObj, true );
2261   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__  ) );
2262   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__  ) );
2263
2264   END_TEST;
2265 }
2266
2267 int UtcDaliRenderTaskOnce05(void)
2268 {
2269   TestApplication application;
2270
2271   tet_infoline("Testing RenderTask Render Once GlSync\n"
2272                "Switch from Render always after ready to render once with resources unready\n"
2273                "PRE: Everything ready to render\n"
2274                "POST: Finished signal sent once");
2275
2276   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2277   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2278   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2279   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2280   drawTrace.Enable(true);
2281
2282   Actor rootActor = Actor::New();
2283   Stage::GetCurrent().Add( rootActor );
2284
2285   CameraActor offscreenCameraActor = CameraActor::New();
2286   Stage::GetCurrent().Add( offscreenCameraActor );
2287   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED);
2288   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2289   Integration::ResourceId imageRequestId = imageRequest->GetId();
2290   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2291   Stage::GetCurrent().Add(secondRootActor);
2292
2293   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
2294   bool finished = false;
2295   RenderTaskFinished renderTaskFinished( finished );
2296   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2297   application.SendNotification();
2298
2299   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2300   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2301   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2302
2303   // CHANGE TO RENDER ONCE
2304   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2305   application.SendNotification(); //         Input,    Expected  Input,    Expected
2306   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2307   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2308
2309   // FINISH RESOURCE LOADING
2310   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2311   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2312   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2313   DALI_TEST_CHECK( lastSyncObj != NULL );
2314   application.GetPlatform().ClearReadyResources();
2315
2316   sync.SetObjectSynced( lastSyncObj, true );
2317
2318   // Expect: No draw - we've just drawn our render task once, above. No finished signal -
2319   // we won't read the gl sync until the next frame. Continue rendering - we're waiting for
2320   // the sync
2321   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2322
2323   // Expect: 1 final draw - this Update doesn't update the scene, hence render instructions
2324   // from last frame but 1 are still present.
2325   // Finished signal should be true - we've just done the sync.
2326   // Should now stop rendering and updating - nothing left to do.
2327   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,   finished, true, false, __LINE__ ) );
2328
2329   END_TEST;
2330 }
2331
2332 #if 0
2333 //int UtcDaliRenderTaskOnce06(void)
2334 {
2335   TestApplication application;
2336
2337   tet_infoline("Testing RenderTask Render Once GlSync\n"
2338                "During RenderOnce, make ready resources unready before sending first finished signal\n"
2339                "PRE: Everything ready.\n"
2340                "POST: Finished signal sent only once");
2341
2342   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2343   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2344   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2345   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2346   drawTrace.Enable(true);
2347
2348   Actor rootActor = Actor::New();
2349   Stage::GetCurrent().Add( rootActor );
2350
2351   CameraActor offscreenCameraActor = CameraActor::New();
2352   Stage::GetCurrent().Add( offscreenCameraActor );
2353   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED);
2354   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2355   Integration::ResourceId imageRequestId = imageRequest->GetId();
2356   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2357   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2358   application.Render();
2359
2360   Stage::GetCurrent().Add(secondRootActor);
2361   application.GetPlatform().ClearReadyResources();
2362
2363   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
2364   bool finished = false;
2365   RenderTaskFinished renderTaskFinished( finished );
2366   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2367   application.SendNotification();
2368
2369   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2370   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2371   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2372
2373   // CHANGE TO RENDER ONCE, RESOURCES BECOME NOT READY
2374   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2375
2376   // Doesn't work...
2377   ReloadImage(application, secondRootActor.GetImage());
2378   application.SendNotification(); //         Input,    Expected  Input,    Expected
2379
2380   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2381   DALI_TEST_EQUALS( secondRootActor.GetImage().GetLoadingState(), Dali::ResourceLoading, TEST_LOCATION);
2382   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2383
2384   // FINISH RESOURCE LOADING
2385   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2386   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2387   application.GetPlatform().ClearReadyResources();
2388   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2389   DALI_TEST_CHECK( lastSyncObj != NULL );
2390
2391   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2392   sync.SetObjectSynced( lastSyncObj, true );
2393   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__  ) );
2394   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, true, __LINE__  ) );
2395
2396   // Finished rendering - expect no more renders, no more signals:
2397   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2398   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2399   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2400   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2401   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2402   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2403   END_TEST;
2404 }
2405 #endif
2406
2407 int UtcDaliRenderTaskOnce07(void)
2408 {
2409   TestApplication application;
2410
2411   tet_infoline("Testing RenderTask Render Once GLSync\n"
2412                "Render once, Second call to SetRefreshRate(ONCE) triggers only one more finished signal\n"
2413                "PRE: Everything ready\n"
2414                "POST: exactly 1 finished signal per call to SetRefreshRate(ONCE)");
2415
2416   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2417   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2418   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2419   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2420   drawTrace.Enable(true);
2421
2422   Actor rootActor = Actor::New();
2423   Stage::GetCurrent().Add( rootActor );
2424
2425   CameraActor offscreenCameraActor = CameraActor::New();
2426   Stage::GetCurrent().Add( offscreenCameraActor );
2427   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED);
2428   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2429   Integration::ResourceId imageRequestId = imageRequest->GetId();
2430   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2431   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2432   application.Render();
2433   application.GetPlatform().ClearReadyResources();
2434
2435   Stage::GetCurrent().Add(secondRootActor);
2436
2437   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
2438   bool finished = false;
2439   RenderTaskFinished renderTaskFinished( finished );
2440   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2441   application.SendNotification();
2442
2443   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2444   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2445
2446   // CHANGE TO RENDER ONCE,
2447   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2448   application.SendNotification();
2449   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2450   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2451   DALI_TEST_CHECK( lastSyncObj != NULL );
2452
2453   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2454   sync.SetObjectSynced( lastSyncObj, true );
2455   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2456   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false, __LINE__ ) );
2457
2458   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2459   application.SendNotification();
2460   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2461   lastSyncObj = sync.GetLastSyncObject();
2462   DALI_TEST_CHECK( lastSyncObj != NULL );
2463
2464   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2465   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2466   sync.SetObjectSynced( lastSyncObj, true );
2467   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2468   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__ ) );
2469   END_TEST;
2470 }
2471
2472 int UtcDaliRenderTaskOnce08(void)
2473 {
2474   TestApplication application;
2475
2476   tet_infoline("Testing RenderTask Render Once GLSync\n"
2477                "Render once, Call to SetRefreshRate(ONCE) in Finished signal callback triggers "
2478                "another render & another finished signal\n"
2479                "PRE: Everything ready\n"
2480                "POST: exactly 1 finished signal per call to SetRefreshRate(ONCE)");
2481
2482
2483   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2484   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2485   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2486   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2487   sync.GetTrace().Enable(true);
2488   drawTrace.Enable(true);
2489
2490   Actor rootActor = Actor::New();
2491   Stage::GetCurrent().Add( rootActor );
2492
2493   CameraActor offscreenCameraActor = CameraActor::New();
2494   Stage::GetCurrent().Add( offscreenCameraActor );
2495   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED);
2496   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2497   Integration::ResourceId imageRequestId = imageRequest->GetId();
2498   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2499   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2500   application.Render();
2501   application.GetPlatform().ClearReadyResources();
2502
2503   Stage::GetCurrent().Add(secondRootActor);
2504
2505   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, /*GL-SYNC*/ true);
2506   bool finished = false;
2507
2508   ConnectionTracker connectionTracker;
2509   RenderTaskFinishedRenderAgain renderTaskFinishedRenderAgain( finished );
2510   newTask.FinishedSignal().Connect( &connectionTracker, renderTaskFinishedRenderAgain );
2511
2512   application.SendNotification();
2513
2514   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2515   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2516   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2517   DALI_TEST_CHECK( lastSyncObj == NULL );
2518   DALI_TEST_EQUALS( sync.GetTrace().CountMethod( "CreateSyncObject" ), 0, TEST_LOCATION );
2519
2520
2521   // CHANGE TO RENDER ONCE,
2522   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2523   application.SendNotification();
2524   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2525   lastSyncObj = sync.GetLastSyncObject();
2526   DALI_TEST_CHECK( lastSyncObj != NULL );
2527   DALI_TEST_EQUALS( sync.GetNumberOfSyncObjects(), 1, TEST_LOCATION );
2528   DALI_TEST_EQUALS( sync.GetTrace().CountMethod( "CreateSyncObject" ), 1, TEST_LOCATION );
2529
2530   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2531
2532
2533   DALI_TEST_EQUALS( sync.GetNumberOfSyncObjects(), 1, TEST_LOCATION );
2534   DALI_TEST_EQUALS( sync.GetTrace().CountMethod( "CreateSyncObject" ), 1, TEST_LOCATION );
2535
2536   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2537
2538   DALI_TEST_EQUALS( sync.GetNumberOfSyncObjects(), 1, TEST_LOCATION );
2539   DALI_TEST_EQUALS( sync.GetTrace().CountMethod( "CreateSyncObject" ), 1, TEST_LOCATION );
2540
2541   sync.SetObjectSynced( lastSyncObj, true );
2542   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2543   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__ ) );
2544   application.SendNotification();
2545
2546   // Expect SetRefreshRate to have been called again
2547   // Prevent next finished signal calling refresh once again
2548   RenderTaskFinished renderTaskFinished( finished );
2549   connectionTracker.DisconnectAll();
2550   newTask.FinishedSignal().Connect( &connectionTracker, renderTaskFinished );
2551   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2552   lastSyncObj = sync.GetLastSyncObject();
2553   DALI_TEST_CHECK( lastSyncObj != NULL );
2554
2555   sync.SetObjectSynced( lastSyncObj, true );
2556   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2557   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__ ) );
2558   END_TEST;
2559 }
2560
2561
2562 int UtcDaliRenderTaskOnce09(void)
2563 {
2564   TestApplication application;
2565
2566   tet_infoline("Testing RenderTask Render Once GlSync\n"
2567                "SetRefreshRate(ONCE) again before first finished signal has been sent.\n"
2568                "PRE: resources ready\n"
2569                "POST: Only 1 finished signal sent.");
2570
2571   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2572   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2573   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2574   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2575   drawTrace.Enable(true);
2576
2577   Actor rootActor = Actor::New();
2578   Stage::GetCurrent().Add( rootActor );
2579
2580   CameraActor offscreenCameraActor = CameraActor::New();
2581   Stage::GetCurrent().Add( offscreenCameraActor );
2582   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED);
2583   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2584   Integration::ResourceId imageRequestId = imageRequest->GetId();
2585   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2586   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2587   application.Render();
2588   application.GetPlatform().ClearReadyResources();
2589
2590   Stage::GetCurrent().Add(secondRootActor);
2591
2592   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
2593   bool finished = false;
2594   RenderTaskFinished renderTaskFinished( finished );
2595   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2596   application.SendNotification();
2597
2598   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2599   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2600
2601   // CHANGE TO RENDER ONCE,
2602   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2603   application.SendNotification();
2604   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2605   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2606   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2607
2608   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2609   application.SendNotification();
2610   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2611   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2612   DALI_TEST_CHECK( lastSyncObj != NULL );
2613
2614   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2615   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2616   sync.SetObjectSynced( lastSyncObj, true );
2617   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2618   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__  ) );
2619
2620   END_TEST;
2621 }
2622
2623 int UtcDaliRenderTaskOnce10(void)
2624 {
2625   TestApplication application;
2626
2627   tet_infoline("Testing RenderTask Render Once GlSync\n"
2628                "SetRefreshRate(ONCE), resource load failed completes render task.\n"
2629                "PRE: resources not ready\n"
2630                "POST: Only 1 finished signal sent.");
2631
2632   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2633   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2634   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2635   drawTrace.Enable(true);
2636
2637   Actor rootActor = Actor::New();
2638   Stage::GetCurrent().Add( rootActor );
2639
2640   CameraActor offscreenCameraActor = CameraActor::New();
2641   Stage::GetCurrent().Add( offscreenCameraActor );
2642   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED);
2643   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2644   Integration::ResourceId imageRequestId = imageRequest->GetId();
2645   Stage::GetCurrent().Add(secondRootActor);
2646
2647   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2648   bool finished = false;
2649   RenderTaskFinished renderTaskFinished( finished );
2650   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2651   application.SendNotification();
2652
2653   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2654   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2655   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2656
2657   // CHANGE TO RENDER ONCE,
2658   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2659   application.SendNotification();
2660   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2661   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2662   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2663
2664   tet_printf("  FailImageLoad\n");
2665
2666   FailImageLoad(application, imageRequestId); // Need to run Update again for this to complete
2667
2668   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) ); // nothing to draw
2669   application.SendNotification();
2670
2671   // load is now failed so there's nothing more to render in the render task
2672   // Expect finished signal, as all resources are complete
2673   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__ ) );
2674
2675   END_TEST;
2676 }
2677
2678 int UtcDaliRenderTaskOnceNoSync01(void)
2679 {
2680   TestApplication application;
2681
2682   tet_infoline("Testing RenderTask Render Once, using loading image\nPRE: Resources not ready, Source not visible\nPOST: Finished signal sent once only");
2683
2684   // SETUP AN OFFSCREEN RENDER TASK
2685   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2686   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2687   drawTrace.Enable(true);
2688
2689   Actor rootActor = Actor::New();
2690   Stage::GetCurrent().Add( rootActor );
2691
2692   CameraActor offscreenCameraActor = CameraActor::New();
2693   Stage::GetCurrent().Add( offscreenCameraActor );
2694   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED);
2695   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2696   Integration::ResourceId imageRequestId = imageRequest->GetId();
2697   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2698
2699   Stage::GetCurrent().Add(secondRootActor);
2700
2701   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, false);
2702   bool finished = false;
2703   RenderTaskFinished renderTaskFinished( finished );
2704   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2705   application.SendNotification();
2706
2707   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2708   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2709   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2710
2711   // FINISH RESOURCE LOADING - expect immediate rendering yet
2712   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2713   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2714   application.GetPlatform().ClearReadyResources();
2715   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__ ) );
2716   END_TEST;
2717 }
2718
2719 int UtcDaliRenderTaskOnceNoSync02(void)
2720 {
2721   TestApplication application;
2722
2723   tet_infoline("Testing RenderTask Render Once, using Mesh which accesses texture through sampler with loading image.\n"
2724                "PRE: Resources not ready\nPOST: Finished signal sent once only");
2725   // SETUP AN OFFSCREEN RENDER TASK
2726   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2727   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2728   drawTrace.Enable(true);
2729
2730   Actor rootActor = Actor::New();
2731   Stage::GetCurrent().Add( rootActor );
2732
2733   CameraActor offscreenCameraActor = CameraActor::New();
2734   Stage::GetCurrent().Add( offscreenCameraActor );
2735
2736   Shader shader = CreateShader();
2737   Image image = CreateLoadingImage(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED);
2738   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2739   Integration::ResourceId imageRequestId = imageRequest->GetId();
2740   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2741   TextureSet textureSet = CreateTextureSet( image );
2742
2743   Geometry geometry = Geometry::QUAD();
2744   Renderer renderer = Renderer::New(geometry, shader);
2745   renderer.SetTextures( textureSet );
2746   Actor secondRootActor = Actor::New();
2747   secondRootActor.AddRenderer(renderer);
2748   secondRootActor.SetSize(100, 100);
2749   Stage::GetCurrent().Add(secondRootActor);
2750
2751   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, false);
2752   bool finished = false;
2753   RenderTaskFinished renderTaskFinished( finished );
2754   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2755   application.SendNotification();
2756
2757   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2758   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2759   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2760
2761   // FINISH RESOURCE LOADING - expect immediate rendering yet
2762   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2763   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2764   application.GetPlatform().ClearReadyResources();
2765   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__ ) );
2766
2767   END_TEST;
2768 }
2769
2770 int UtcDaliRenderTaskOnceNoSync03(void)
2771 {
2772   TestApplication application;
2773
2774   tet_infoline("Testing RenderTask Render Once, using loading image. Switch from render always after ready to render once\n"
2775                "PRE: Render task ready, Image not loaded\n"
2776                "POST: Finished signal sent only once");
2777
2778   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2779   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2780   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2781   drawTrace.Enable(true);
2782
2783   Actor rootActor = Actor::New();
2784   Stage::GetCurrent().Add( rootActor );
2785
2786   CameraActor offscreenCameraActor = CameraActor::New();
2787   Stage::GetCurrent().Add( offscreenCameraActor );
2788   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED);
2789   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2790   Integration::ResourceId imageRequestId = imageRequest->GetId();
2791   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2792   Stage::GetCurrent().Add(secondRootActor);
2793
2794   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2795   bool finished = false;
2796   RenderTaskFinished renderTaskFinished( finished );
2797   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2798   application.SendNotification();
2799
2800   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2801   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2802   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2803
2804   // FINISH RESOURCE LOADING
2805   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2806   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2807   application.GetPlatform().ClearReadyResources();
2808
2809   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2810   application.SendNotification(); //         Input,    Expected  Input,    Expected
2811   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2812   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__ ) );
2813   END_TEST;
2814 }
2815
2816 int UtcDaliRenderTaskOnceNoSync04(void)
2817 {
2818   TestApplication application;
2819
2820   tet_infoline("Testing RenderTask Render Once, using Mesh which accesses texture through sampler with loading image.\n"
2821                "Switch from render always after ready to render once\n"
2822                "PRE: Render task ready, Image not loaded\n"
2823                "POST: Finished signal sent only once");
2824
2825   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2826   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2827   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2828   drawTrace.Enable(true);
2829
2830   Actor rootActor = Actor::New();
2831   Stage::GetCurrent().Add( rootActor );
2832
2833   CameraActor offscreenCameraActor = CameraActor::New();
2834   Stage::GetCurrent().Add( offscreenCameraActor );
2835
2836   Shader shader = CreateShader();
2837   Image image = CreateLoadingImage(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED);
2838   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2839   Integration::ResourceId imageRequestId = imageRequest->GetId();
2840   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2841   TextureSet textureSet = CreateTextureSet( image );
2842
2843   Geometry geometry = Geometry::QUAD();
2844   Renderer renderer = Renderer::New(geometry, shader);
2845   renderer.SetTextures( textureSet );
2846   Actor secondRootActor = Actor::New();
2847   secondRootActor.AddRenderer(renderer);
2848   secondRootActor.SetSize(100, 100);
2849   Stage::GetCurrent().Add(secondRootActor);
2850
2851
2852   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2853   bool finished = false;
2854   RenderTaskFinished renderTaskFinished( finished );
2855   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2856   application.SendNotification();
2857
2858   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2859   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2860   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2861
2862   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2863   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2864   DALI_TEST_CHECK( lastSyncObj == NULL );
2865
2866   // FINISH RESOURCE LOADING
2867   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2868   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2869   application.GetPlatform().ClearReadyResources();
2870
2871   lastSyncObj = sync.GetLastSyncObject();
2872   DALI_TEST_CHECK( lastSyncObj == NULL );
2873
2874   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2875   application.SendNotification(); //         Input,    Expected  Input,    Expected
2876   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2877   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__ ) );
2878
2879   lastSyncObj = sync.GetLastSyncObject();
2880   DALI_TEST_CHECK( lastSyncObj == NULL );
2881
2882   END_TEST;
2883 }
2884
2885 int UtcDaliRenderTaskOnceNoSync05(void)
2886 {
2887   TestApplication application;
2888
2889   tet_infoline("Testing RenderTask Render Once\n"
2890                "Switch from Render always after ready to render once with resources unready\n"
2891                "PRE: Everything ready to render\n"
2892                "POST: Finished signal sent once");
2893
2894   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2895   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2896   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2897   drawTrace.Enable(true);
2898
2899   Actor rootActor = Actor::New();
2900   Stage::GetCurrent().Add( rootActor );
2901
2902   CameraActor offscreenCameraActor = CameraActor::New();
2903   Stage::GetCurrent().Add( offscreenCameraActor );
2904   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED);
2905   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2906   Integration::ResourceId imageRequestId = imageRequest->GetId();
2907   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2908   Stage::GetCurrent().Add(secondRootActor);
2909
2910   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2911   bool finished = false;
2912   RenderTaskFinished renderTaskFinished( finished );
2913   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2914   application.SendNotification();
2915
2916   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2917   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2918   DALI_TEST_CHECK( lastSyncObj == NULL );
2919
2920   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2921   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2922   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2923
2924   // CHANGE TO RENDER ONCE
2925   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2926   application.SendNotification(); //         Input,    Expected  Input,    Expected
2927   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2928   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2929
2930   // FINISH RESOURCE LOADING
2931   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2932   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2933   application.GetPlatform().ClearReadyResources();
2934   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__ ) );
2935   END_TEST;
2936 }
2937
2938 #if 0
2939 //int UtcDaliRenderTaskOnceNoSync06(void)
2940 {
2941   TestApplication application;
2942
2943   tet_infoline("Testing RenderTask Render Once\n"
2944                "During RenderOnce, make ready resources unready before sending first finished signal\n"
2945                "PRE: Everything ready.\n"
2946                "POST: Finished signal sent only once");
2947
2948   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2949   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2950   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2951   drawTrace.Enable(true);
2952
2953   Actor rootActor = Actor::New();
2954   Stage::GetCurrent().Add( rootActor );
2955
2956   CameraActor offscreenCameraActor = CameraActor::New();
2957   Stage::GetCurrent().Add( offscreenCameraActor );
2958   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED);
2959   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2960   Integration::ResourceId imageRequestId = imageRequest->GetId();
2961   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2962   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2963   application.Render();
2964   application.GetPlatform().ClearReadyResources();
2965
2966   Stage::GetCurrent().Add(secondRootActor);
2967
2968   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2969   bool finished = false;
2970   RenderTaskFinished renderTaskFinished( finished );
2971   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2972   application.SendNotification();
2973
2974   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2975   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2976   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2977
2978   // CHANGE TO RENDER ONCE, RESOURCES BECOME NOT READY
2979   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2980
2981   // Doesn't work...
2982   ReloadImage(application, secondRootActor.GetImage());
2983   application.SendNotification(); //         Input,    Expected  Input,    Expected
2984
2985   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2986   DALI_TEST_EQUALS( secondRootActor.GetImage().GetLoadingState(), Dali::ResourceLoading, TEST_LOCATION);
2987   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
2988
2989   // FINISH RESOURCE LOADING
2990   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2991   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, true, true, __LINE__ ) );
2992   application.GetPlatform().ClearReadyResources();
2993   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2994   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__  ) );
2995   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2996   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__ ) );
2997   END_TEST;
2998 }
2999 #endif
3000
3001 int UtcDaliRenderTaskOnceNoSync07(void)
3002 {
3003   TestApplication application;
3004
3005   tet_infoline("Testing RenderTask Render Once\n"
3006                "Render once, Second call to SetRefreshRate(ONCE) triggers only one more finished signal\n"
3007                "PRE: Everything ready\n"
3008                "POST: exactly 1 finished signal per call to SetRefreshRate(ONCE)");
3009
3010   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
3011   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
3012   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
3013   drawTrace.Enable(true);
3014
3015   Actor rootActor = Actor::New();
3016   Stage::GetCurrent().Add( rootActor );
3017
3018   CameraActor offscreenCameraActor = CameraActor::New();
3019   Stage::GetCurrent().Add( offscreenCameraActor );
3020   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED);
3021   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
3022   Integration::ResourceId imageRequestId = imageRequest->GetId();
3023   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
3024   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
3025   application.Render();
3026   application.GetPlatform().ClearReadyResources();
3027
3028   Stage::GetCurrent().Add(secondRootActor);
3029
3030   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
3031   bool finished = false;
3032   RenderTaskFinished renderTaskFinished( finished );
3033   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
3034   application.SendNotification();
3035
3036   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
3037   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
3038
3039   // CHANGE TO RENDER ONCE,
3040   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
3041   application.SendNotification();
3042   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
3043   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false, __LINE__ ) );
3044
3045   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
3046   application.SendNotification();
3047   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
3048   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false, __LINE__ ) );
3049   END_TEST;
3050 }
3051
3052 int UtcDaliRenderTaskOnceNoSync08(void)
3053 {
3054   TestApplication application;
3055
3056   tet_infoline("Testing RenderTask Render Once\n"
3057                "Render once, Call to SetRefreshRate(ONCE) in Finished signal callback triggers\n"
3058                "another render & another finished signal\n"
3059                "PRE: Everything ready\n"
3060                "POST: exactly 1 finished signal per call to SetRefreshRate(ONCE)");
3061
3062
3063   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
3064   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
3065   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
3066   drawTrace.Enable(true);
3067
3068   Actor rootActor = Actor::New();
3069   Stage::GetCurrent().Add( rootActor );
3070
3071   CameraActor offscreenCameraActor = CameraActor::New();
3072   Stage::GetCurrent().Add( offscreenCameraActor );
3073   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED);
3074   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
3075   Integration::ResourceId imageRequestId = imageRequest->GetId();
3076   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
3077   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
3078   application.Render();
3079   application.GetPlatform().ClearReadyResources();
3080
3081   Stage::GetCurrent().Add(secondRootActor);
3082
3083   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
3084   bool finished = false;
3085
3086   ConnectionTracker connectionTracker;
3087   RenderTaskFinishedRenderAgain renderTaskFinishedRenderAgain( finished );
3088   newTask.FinishedSignal().Connect( &connectionTracker, renderTaskFinishedRenderAgain );
3089
3090   application.SendNotification();
3091
3092   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
3093   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
3094
3095   // CHANGE TO RENDER ONCE,
3096   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
3097   application.SendNotification();
3098   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
3099   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false, __LINE__ ) );
3100
3101   // Expect SetRefreshRate to have been called again
3102   // Prevent next finished signal calling refresh once again
3103   RenderTaskFinished renderTaskFinished( finished );
3104   connectionTracker.DisconnectAll();
3105   newTask.FinishedSignal().Connect( &connectionTracker, renderTaskFinished );
3106
3107   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
3108   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false, __LINE__ ) );
3109   END_TEST;
3110 }
3111
3112
3113 int UtcDaliRenderTaskOnceNoSync09(void)
3114 {
3115   TestApplication application;
3116
3117   tet_infoline("Testing RenderTask Render Once\n"
3118                "SetRefreshRate(ONCE) again before first finished signal has been sent.\n"
3119                "PRE: resources ready\n"
3120                "POST: Only 1 finished signal sent.");
3121
3122   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
3123   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
3124   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
3125   drawTrace.Enable(true);
3126
3127   Actor rootActor = Actor::New();
3128   Stage::GetCurrent().Add( rootActor );
3129
3130   CameraActor offscreenCameraActor = CameraActor::New();
3131   Stage::GetCurrent().Add( offscreenCameraActor );
3132   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED);
3133   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
3134   Integration::ResourceId imageRequestId = imageRequest->GetId();
3135   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
3136   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
3137   application.Render();
3138   application.GetPlatform().ClearReadyResources();
3139
3140   Stage::GetCurrent().Add(secondRootActor);
3141
3142   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
3143   bool finished = false;
3144   RenderTaskFinished renderTaskFinished( finished );
3145   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
3146   application.SendNotification();
3147
3148   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
3149   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
3150
3151   // CHANGE TO RENDER ONCE,
3152   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
3153   application.SendNotification();
3154   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
3155   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false, __LINE__ ) );
3156
3157   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
3158   application.SendNotification();
3159   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
3160   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false, __LINE__ ) );
3161   END_TEST;
3162 }
3163
3164 int UtcDaliRenderTaskOnceNoSync10(void)
3165 {
3166   TestApplication application;
3167
3168   tet_infoline("Testing RenderTask Render Once\n"
3169                "SetRefreshRate(ONCE), resource load failed, completes render task.\n"
3170                "PRE: resources not ready\n"
3171                "POST: Only 1 finished signal sent.");
3172
3173   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
3174   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
3175   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
3176   drawTrace.Enable(true);
3177
3178   Actor rootActor = Actor::New();
3179   Stage::GetCurrent().Add( rootActor );
3180
3181   CameraActor offscreenCameraActor = CameraActor::New();
3182   Stage::GetCurrent().Add( offscreenCameraActor );
3183   Actor secondRootActor = CreateLoadingActor(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED);
3184   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
3185   Integration::ResourceId imageRequestId = imageRequest->GetId();
3186   Stage::GetCurrent().Add(secondRootActor);
3187
3188   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
3189   bool finished = false;
3190   RenderTaskFinished renderTaskFinished( finished );
3191   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
3192   application.SendNotification();
3193
3194   // START PROCESS/RENDER                    Input,     Expected  Input,    Expected
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   // CHANGE TO RENDER ONCE,
3199   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
3200   application.SendNotification();
3201   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
3202   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
3203   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) );
3204
3205   FailImageLoad(application, imageRequestId); // Need to run Update again for this to complete
3206   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true, __LINE__ ) ); // nothing to draw
3207   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, true,  false, __LINE__ ) );
3208
3209   END_TEST;
3210 }
3211
3212
3213
3214 int UtcDaliRenderTaskOnceChain01(void)
3215 {
3216   TestApplication application;
3217
3218   tet_infoline("Testing RenderTask Render Once Chained render tasks\n"
3219                "SetRefreshRate(ONCE), resource load completes, both render tasks render.\n"
3220                "PRE: resources not ready\n"
3221                "POST: 2 finished signals sent.");
3222
3223   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
3224   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
3225   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
3226   drawTrace.Enable(true);
3227
3228   Actor defaultRootActor = Actor::New(); // Root for default RT
3229   Stage::GetCurrent().Add( defaultRootActor );
3230
3231   CameraActor offscreenCameraActor = CameraActor::New();
3232   Stage::GetCurrent().Add( offscreenCameraActor );
3233   Actor firstRootActor = CreateLoadingActor(application, "aFile.jpg", ResourceImage::IMMEDIATE, Image::UNUSED);
3234   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
3235   Integration::ResourceId imageRequestId = imageRequest->GetId();
3236   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
3237   Stage::GetCurrent().Add(firstRootActor);
3238
3239   // first render task
3240   RenderTask firstTask = CreateRenderTask(application, offscreenCameraActor, defaultRootActor, firstRootActor, RenderTask::REFRESH_ONCE, false);
3241   bool firstFinished = false;
3242   RenderTaskFinished renderTask1Finished( firstFinished );
3243   firstTask.FinishedSignal().Connect( &application, renderTask1Finished );
3244
3245   // Second render task
3246   FrameBufferImage fbo = firstTask.GetTargetFrameBuffer();
3247   Actor secondRootActor = CreateRenderableActor( fbo );
3248   Stage::GetCurrent().Add(secondRootActor);
3249   RenderTask secondTask = CreateRenderTask(application, offscreenCameraActor, defaultRootActor, secondRootActor, RenderTask::REFRESH_ONCE, false);
3250   bool secondFinished = false;
3251   RenderTaskFinished renderTask2Finished( secondFinished );
3252   secondTask.FinishedSignal().Connect( &application, renderTask2Finished );
3253
3254   application.SendNotification();
3255
3256   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
3257   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,  firstFinished, false, true, __LINE__ ) );
3258   DALI_TEST_CHECK( firstFinished == false );
3259   DALI_TEST_CHECK( secondFinished == false );
3260   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,  firstFinished, false, true, __LINE__ ) );
3261   DALI_TEST_CHECK( firstFinished == false );
3262   DALI_TEST_CHECK( secondFinished == false );
3263
3264   CompleteImageLoad(application, imageRequestId, imageType);
3265   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,  firstFinished, false, true, __LINE__ ) );
3266   DALI_TEST_CHECK( firstFinished == false );
3267   DALI_TEST_CHECK( secondFinished == false );
3268
3269   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,  firstFinished, true, true, __LINE__ ) );
3270   DALI_TEST_CHECK( firstFinished == true );
3271   DALI_TEST_CHECK( secondFinished == false );
3272
3273   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,  secondFinished, true, false, __LINE__ ) );
3274   DALI_TEST_CHECK( secondFinished == true );
3275
3276   END_TEST;
3277 }
3278
3279 int UtcDaliRenderTaskProperties(void)
3280 {
3281   TestApplication application;
3282
3283   RenderTask task = Stage::GetCurrent().GetRenderTaskList().CreateTask();
3284
3285   Property::IndexContainer indices;
3286   task.GetPropertyIndices( indices );
3287   DALI_TEST_CHECK( indices.Size() );
3288   DALI_TEST_EQUALS( indices.Size(), task.GetPropertyCount(), TEST_LOCATION );
3289   END_TEST;
3290 }
3291
3292 int UtcDaliRenderTaskSetScreenToFrameBufferMappingActor(void)
3293 {
3294   TestApplication application;
3295   tet_infoline("Testing RenderTask::SetScreenToFrameBufferMappingActor ");
3296
3297   Stage stage = Stage::GetCurrent();
3298   Size stageSize = stage.GetSize();
3299   Actor mappingActor = Actor::New();
3300   Vector2 scale( 0.6f, 0.75f);
3301   Vector2 offset( stageSize.x*0.1f, stageSize.y*0.15f);
3302   mappingActor.SetSize( stageSize * scale );
3303   mappingActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
3304   mappingActor.SetPosition( offset.x, offset.y );
3305   stage.Add( mappingActor );
3306
3307   Actor offscreenActor = Actor::New();
3308   offscreenActor.SetSize( stageSize );
3309   offscreenActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
3310   stage.Add( offscreenActor );
3311
3312   RenderTaskList taskList = stage.GetRenderTaskList();
3313   RenderTask renderTask = taskList.CreateTask();
3314   FrameBufferImage frameBufferImage =  FrameBufferImage::New(stageSize.width*scale.x, stageSize.height*scale.y, Pixel::A8, Image::NEVER);
3315   renderTask.SetSourceActor( offscreenActor );
3316   renderTask.SetExclusive( true );
3317   renderTask.SetInputEnabled( true );
3318   renderTask.SetTargetFrameBuffer( frameBufferImage );
3319   renderTask.SetRefreshRate( RenderTask::REFRESH_ONCE );
3320   renderTask.SetScreenToFrameBufferMappingActor( mappingActor );
3321   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
3322
3323   // Render and notify
3324   application.SendNotification();
3325   application.Render();
3326   application.Render();
3327   application.SendNotification();
3328
3329   Vector2 screenCoordinates( stageSize.x * 0.05f, stageSize.y * 0.05f );
3330   Dali::HitTestAlgorithm::Results results;
3331   DALI_TEST_CHECK( !results.actor );
3332   DALI_TEST_EQUALS( Vector2::ZERO, results.actorCoordinates, 0.1f, TEST_LOCATION );
3333   // miss expected, results not changed
3334   DALI_TEST_CHECK( false == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
3335   DALI_TEST_CHECK( !results.actor );
3336   DALI_TEST_EQUALS( Vector2::ZERO, results.actorCoordinates, 0.1f, TEST_LOCATION );
3337
3338   screenCoordinates.x = stageSize.x * 0.265f;
3339   screenCoordinates.y = stageSize.y * 0.33f;
3340   results.actor = Actor();
3341   results.actorCoordinates = Vector2::ZERO;
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   DALI_TEST_EQUALS( (screenCoordinates-offset)/scale , results.actorCoordinates, 0.1f, TEST_LOCATION );
3346
3347   screenCoordinates.x = stageSize.x * 0.435f;
3348   screenCoordinates.y = stageSize.y * 0.52f;
3349   // hit expected, results changed
3350   DALI_TEST_CHECK( true == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
3351   DALI_TEST_CHECK( results.actor  == offscreenActor );
3352   const Vector2 expectedCoordinates = (screenCoordinates-offset)/scale;
3353   DALI_TEST_EQUALS( expectedCoordinates , results.actorCoordinates, 0.1f, TEST_LOCATION );
3354
3355   screenCoordinates.x = stageSize.x * 0.65f;
3356   screenCoordinates.y = stageSize.y * 0.95f;
3357   // miss expected, results not changed
3358   DALI_TEST_CHECK( false == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
3359   DALI_TEST_CHECK( results.actor  == offscreenActor );
3360   DALI_TEST_EQUALS( expectedCoordinates , results.actorCoordinates, 0.1f, TEST_LOCATION );
3361   END_TEST;
3362 }
3363
3364 int UtcDaliRenderTaskFinishInvisibleSourceActor(void)
3365 {
3366   TestApplication application;
3367
3368   tet_infoline("Testing RenderTask::FinishInvisibleSourceActor()");
3369
3370   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
3371   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
3372
3373   CameraActor offscreenCameraActor = CameraActor::New();
3374
3375   Stage::GetCurrent().Add( offscreenCameraActor );
3376
3377   BufferImage image = BufferImage::New( 10, 10 );
3378   Actor rootActor = CreateRenderableActor( image );
3379   rootActor.SetSize( 10, 10 );
3380   rootActor.SetVisible(false);
3381   Stage::GetCurrent().Add( rootActor );
3382
3383   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
3384   NativeImageInterfacePtr testNativeImagePtr = TestNativeImage::New(10, 10);
3385   FrameBufferImage frameBufferImage = FrameBufferImage::New( *testNativeImagePtr.Get() );
3386
3387   // Flush all outstanding messages
3388   application.SendNotification();
3389   application.Render();
3390
3391   RenderTask newTask = taskList.CreateTask();
3392   newTask.SetCameraActor( offscreenCameraActor );
3393   newTask.SetSourceActor( rootActor );
3394   newTask.SetInputEnabled( false );
3395   newTask.SetClearColor( Vector4( 0.f, 0.f, 0.f, 0.f ) );
3396   newTask.SetClearEnabled( true );
3397   newTask.SetExclusive( true );
3398   newTask.SetRefreshRate( RenderTask::REFRESH_ONCE );
3399   newTask.SetTargetFrameBuffer( frameBufferImage );
3400   newTask.SetProperty( RenderTask::Property::REQUIRES_SYNC, true );
3401
3402   // Framebuffer doesn't actually get created until Connected, i.e. by previous line
3403
3404   bool finished = false;
3405   RenderTaskFinished renderTaskFinished( finished );
3406   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
3407
3408   // Flush the queue and render.
3409   application.SendNotification();
3410
3411   // 1 render to process render task, then wait for sync before finished msg is sent
3412   // from update to the event thread.
3413
3414   application.Render();
3415   application.SendNotification();
3416   DALI_TEST_CHECK( !finished );
3417
3418   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
3419   DALI_TEST_CHECK( lastSyncObj != NULL );
3420
3421   application.Render();
3422   DALI_TEST_EQUALS( (Integration::KeepUpdating::Reasons)(application.GetUpdateStatus() & Integration::KeepUpdating::RENDER_TASK_SYNC), Integration::KeepUpdating::RENDER_TASK_SYNC, TEST_LOCATION );
3423   application.SendNotification();
3424   DALI_TEST_CHECK( !finished );
3425
3426   application.Render();
3427   DALI_TEST_EQUALS( (Integration::KeepUpdating::Reasons)(application.GetUpdateStatus() & Integration::KeepUpdating::RENDER_TASK_SYNC), Integration::KeepUpdating::RENDER_TASK_SYNC, TEST_LOCATION );
3428   application.SendNotification();
3429   DALI_TEST_CHECK( ! finished );
3430
3431   sync.SetObjectSynced( lastSyncObj, true );
3432
3433   application.Render();
3434   application.SendNotification();
3435   DALI_TEST_CHECK( !finished );
3436
3437   application.Render();
3438   application.SendNotification();
3439   DALI_TEST_CHECK( finished );
3440   finished = false;
3441
3442   application.Render(); // Double check no more finished signal
3443   application.SendNotification();
3444   DALI_TEST_CHECK( ! finished );
3445
3446   END_TEST;
3447 }
3448
3449 int UtcDaliRenderTaskFinishMissingImage(void)
3450 {
3451   TestApplication application;
3452
3453   // Previously we had bugs where not having a resource ID would cause render-tasks to wait forever
3454   tet_infoline("Testing RenderTask::SignalFinished() when an Actor has no Image set");
3455
3456   Stage stage = Stage::GetCurrent();
3457
3458   BufferImage image = BufferImage::New( 10, 10 );
3459   Actor rootActor = CreateRenderableActor( image );
3460   rootActor.SetSize( 10, 10 );
3461   stage.Add( rootActor );
3462
3463   Actor actorWithMissingImage = CreateRenderableActor( Image() );
3464   actorWithMissingImage.SetSize( 10, 10 );
3465   stage.Add( actorWithMissingImage );
3466
3467   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
3468   RenderTask newTask = taskList.CreateTask();
3469   newTask.SetInputEnabled( false );
3470   newTask.SetClearColor( Vector4( 0.f, 0.f, 0.f, 0.f ) );
3471   newTask.SetClearEnabled( true );
3472   newTask.SetExclusive( true );
3473   newTask.SetRefreshRate( RenderTask::REFRESH_ONCE );
3474
3475   bool finished = false;
3476   RenderTaskFinished renderTaskFinished( finished );
3477   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
3478
3479   // 1 render to process render task, then 1 before finished msg is sent from update to the event thread.
3480   application.SendNotification();
3481   application.Render();
3482   application.Render();
3483
3484   application.SendNotification();
3485   DALI_TEST_CHECK( finished );
3486
3487   END_TEST;
3488 }
3489
3490 int UtcDaliRenderTaskWorldToViewport(void)
3491 {
3492   TestApplication application( static_cast<size_t>(400), static_cast<size_t>(400) ); // square surface
3493
3494   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
3495
3496   Actor actor = Actor::New();
3497   actor.SetSize(100.0f, 100.0f);
3498   actor.SetPosition( Vector3(0.0, 0.0, 0.0) );
3499
3500   actor.SetParentOrigin( Vector3(0.5, 0.5, 0.5) );
3501   actor.SetAnchorPoint( Vector3(0.5, 0.5, 0.5) );
3502
3503   Stage::GetCurrent().Add(actor);
3504
3505   application.SendNotification();
3506   application.Render();
3507   application.SendNotification();
3508
3509   RenderTask task = taskList.GetTask( 0u );
3510
3511   CameraActor camera = task.GetCameraActor();
3512
3513   Vector2 screenSize = task.GetCurrentViewportSize();
3514
3515   float screenX = 0.0;
3516   float screenY = 0.0;
3517
3518   bool ok = task.WorldToViewport(actor.GetCurrentWorldPosition(), screenX, screenY);
3519   DALI_TEST_CHECK(ok == true);
3520
3521   DALI_TEST_EQUALS(screenX, screenSize.x/2, Math::MACHINE_EPSILON_10000, TEST_LOCATION);
3522   DALI_TEST_EQUALS(screenY, screenSize.y/2, Math::MACHINE_EPSILON_10000, TEST_LOCATION);
3523
3524   Actor actor2 = Actor::New();
3525   float actor2Size = 100.f;
3526   actor2.SetSize( actor2Size, actor2Size );
3527   actor2.SetPosition( Vector3(0.0, 0.0, 0.0) );
3528   actor2.SetParentOrigin( Vector3(0.5, 0.5, 0.0) );
3529   actor2.SetAnchorPoint( Vector3(0.5, 0.5, 0.0) );
3530   Stage::GetCurrent().Add( actor2 );
3531   actor2.Add(actor);
3532   actor.SetParentOrigin( Vector3(0,0,0) );
3533
3534   application.SendNotification();
3535   application.Render();
3536   application.SendNotification();
3537
3538   ok = task.WorldToViewport(actor.GetCurrentWorldPosition(), screenX, screenY);
3539   DALI_TEST_CHECK(ok == true);
3540
3541   DALI_TEST_EQUALS(screenX, screenSize.x/2 - actor2Size/2, Math::MACHINE_EPSILON_10000, TEST_LOCATION);
3542   DALI_TEST_EQUALS(screenY, screenSize.y/2 - actor2Size/2, Math::MACHINE_EPSILON_10000, TEST_LOCATION);
3543
3544   END_TEST;
3545 }
3546
3547
3548 int UtcDaliRenderTaskViewportToLocal(void)
3549 {
3550   TestApplication application;
3551   Actor actor = Actor::New();
3552   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
3553   actor.SetSize(100.0f, 100.0f);
3554   actor.SetPosition(10.0f, 10.0f);
3555   Stage::GetCurrent().Add(actor);
3556
3557   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
3558   RenderTask task = taskList.GetTask( 0u );
3559
3560   // flush the queue and render once
3561   application.SendNotification();
3562   application.Render();
3563   application.SendNotification();
3564   application.Render();
3565
3566   float localX;
3567   float localY;
3568
3569   float rtLocalX;
3570   float rtLocalY;
3571
3572   float screenX = 50.0f;
3573   float screenY = 50.0f;
3574
3575   DALI_TEST_CHECK( actor.ScreenToLocal(localX, localY, screenX, screenY) );
3576
3577   DALI_TEST_CHECK( task.ViewportToLocal(actor, screenX, screenY, rtLocalX, rtLocalY ) );
3578
3579   DALI_TEST_EQUALS(localX, rtLocalX, 0.01f, TEST_LOCATION);
3580   DALI_TEST_EQUALS(localY, rtLocalY, 0.01f, TEST_LOCATION);
3581
3582   END_TEST;
3583
3584 }