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