Ensure cached values of properties animated using AnimateTo are updated
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-RenderTask.cpp
1 /*
2  * Copyright (c) 2017 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 #include <stdlib.h>
20 #include <dali/public-api/dali-core.h>
21 #include <dali/devel-api/events/hit-test-algorithm.h>
22 #include <dali/devel-api/object/handle-devel.h>
23 #include <dali-test-suite-utils.h>
24 #include <dali/integration-api/debug.h>
25 #include <test-native-image.h>
26
27 #include <mesh-builder.h>
28
29 #define BOOLSTR(x) ((x)?"T":"F")
30
31 //& set: DaliRenderTask
32
33 using namespace Dali;
34
35 void utc_dali_render_task_startup(void)
36 {
37   test_return_value = TET_UNDEF;
38 }
39
40 void utc_dali_render_task_cleanup(void)
41 {
42   test_return_value = TET_PASS;
43 }
44
45 /**
46  * APIs:
47  *
48  * Constructor, Destructor, DownCast, New, copy constructor, assignment operator
49  *
50  * SetSourceActor                      2+ve, 1-ve
51  * GetSourceActor                      1+ve, 1-ve
52  * SetExclusive                        2+ve, 0-ve
53  * IsExclusive                         2+ve, 0-ve
54  * SetInputEnabled                     1+ve, 0-ve
55  * GetInputEnabled                     1+ve, 0-ve
56  * SetCameraActor                      1+ve, 1-ve
57  * GetCameraActor                      1+ve, 1-ve
58  * SetTargetFrameBuffer                1+ve, 1-ve
59  * GetTargetFrameBuffer                1+ve, 1-ve
60  * SetScreenToFrameBufferFunction      1+ve, 1-ve
61  * GetScreenToFrameBufferFunction      1+ve, 1-ve
62  * SetScreenToFrameBufferMappingActor  1+ve, 1-ve
63  * GetScreenToFrameBufferMappingActor  1+ve, 1-ve
64  * SetViewportPosition                 1+ve
65  * GetCurrentViewportPosition          1+ve
66  * SetViewportSize                     1+ve
67  * GetCurrentViewportSize              1+ve
68  * SetViewport                         2+ve, 1-ve
69  * GetViewport                         2+ve, 1-ve
70  * SetClearColor                       1+ve, 1-ve
71  * GetClearColor                       1+ve, 1-ve
72  * SetClearEnabled                     1+ve, 1-ve
73  * GetClearEnabled                     1+ve, 1-ve
74  * SetCullMode
75  * GetCullMode
76  * SetRefreshRate                      Many
77  * GetRefreshRate                      1+ve
78  * FinishedSignal                      1+ve
79  */
80
81 namespace // unnamed namespace
82 {
83
84 const int RENDER_FRAME_INTERVAL = 16;                           ///< Duration of each frame in ms. (at approx 60FPS)
85
86 /*
87  * Simulate time passed by.
88  *
89  * @note this will always process at least 1 frame (1/60 sec)
90  *
91  * @param application Test application instance
92  * @param duration Time to pass in milliseconds.
93  * @return The actual time passed in milliseconds
94  */
95 int Wait(TestApplication& application, int duration = 0)
96 {
97   int time = 0;
98
99   for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
100   {
101     application.SendNotification();
102     application.Render(RENDER_FRAME_INTERVAL);
103     time += RENDER_FRAME_INTERVAL;
104   }
105
106   return time;
107 }
108
109 struct RenderTaskFinished
110 {
111   RenderTaskFinished( bool& finished )
112   : finished( finished )
113   {
114   }
115
116   void operator()( RenderTask& renderTask )
117   {
118     finished = true;
119   }
120
121   bool& finished;
122 };
123
124 struct RenderTaskFinishedRemoveSource
125 {
126   RenderTaskFinishedRemoveSource( bool& finished )
127   : finished( finished ),
128     finishedOnce(false)
129   {
130   }
131
132   void operator()( RenderTask& renderTask )
133   {
134     DALI_TEST_CHECK(finishedOnce == false);
135     finished = true;
136     finishedOnce = true;
137     Actor srcActor = renderTask.GetSourceActor();
138     UnparentAndReset(srcActor);
139   }
140
141   bool& finished;
142   bool finishedOnce;
143 };
144
145 struct RenderTaskFinishedRenderAgain
146 {
147   RenderTaskFinishedRenderAgain( bool& finished )
148   : finished( finished ),
149     finishedOnce(false)
150   {
151   }
152
153   void operator()( RenderTask& renderTask )
154   {
155     DALI_TEST_CHECK(finishedOnce == false);
156     finished = true;
157     finishedOnce = true;
158     renderTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
159   }
160
161   bool& finished;
162   bool finishedOnce;
163 };
164
165
166 bool TestScreenToFrameBufferFunction( Vector2& coordinates )
167 {
168   coordinates = coordinates + Vector2( 1, 2 );
169
170   return true;
171 }
172
173 Actor CreateRenderableActorSuccess(TestApplication& application, std::string filename)
174 {
175   PrepareResourceImage( application, 80u, 80u, Pixel::RGBA8888 );
176   Image image = ResourceImage::New(filename);
177   Actor actor = CreateRenderableActor(image);
178   actor.SetSize( 80, 80 );
179   return actor;
180 }
181
182 Actor CreateRenderableActorFailed(TestApplication& application, std::string filename)
183 {
184   Image image = ResourceImage::New(filename);
185   DALI_TEST_CHECK( image );
186   Actor actor = CreateRenderableActor(image);
187   actor.SetSize( 80, 80 );
188   return actor;
189 }
190
191 Image CreateResourceImage(TestApplication& application, std::string filename)
192 {
193   PrepareResourceImage( application, 80u, 80u, Pixel::RGBA8888 );
194   Image image = ResourceImage::New(filename);
195   DALI_TEST_CHECK( image );
196   return image;
197 }
198
199 RenderTask CreateRenderTask(TestApplication& application,
200                             CameraActor offscreenCamera,
201                             Actor rootActor,       // Reset default render task to point at this actor
202                             Actor secondRootActor, // Source actor
203                             unsigned int refreshRate,
204                             bool glSync)
205 {
206   // Change main render task to use a different root
207   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
208   taskList.GetTask(0u).SetSourceActor( rootActor );
209
210   FrameBufferImage frameBufferImage;
211   if( glSync )
212   {
213     NativeImageInterfacePtr testNativeImagePtr = TestNativeImage::New(10, 10);
214     frameBufferImage= FrameBufferImage::New( *(testNativeImagePtr.Get()) );
215   }
216   else
217   {
218     frameBufferImage = FrameBufferImage::New( 10, 10 );
219   }
220
221   // Don't draw output framebuffer // '
222
223   RenderTask newTask = taskList.CreateTask();
224   newTask.SetCameraActor( offscreenCamera );
225   newTask.SetSourceActor( secondRootActor );
226   newTask.SetInputEnabled( false );
227   newTask.SetClearColor( Vector4( 0.f, 0.f, 0.f, 0.f ) );
228   newTask.SetClearEnabled( true );
229   newTask.SetExclusive( true );
230   newTask.SetRefreshRate( refreshRate );
231   newTask.SetTargetFrameBuffer( frameBufferImage );
232   newTask.SetProperty( RenderTask::Property::REQUIRES_SYNC, glSync );
233   return newTask;
234 }
235
236 bool UpdateRender(TestApplication& application, TraceCallStack& callStack, bool testDrawn, bool& finishedSig, bool testFinished, bool testKeepUpdating, int lineNumber )
237 {
238   finishedSig = false;
239   callStack.Reset();
240
241   tet_printf("TestApplication::UpdateRender().\n");
242
243   application.Render(16);
244   application.SendNotification();
245
246   bool sigPassed = false;
247   if( testFinished )
248   {
249     sigPassed = finishedSig;
250   }
251   else
252   {
253     sigPassed = ! finishedSig;
254   }
255
256   bool drawResult = callStack.FindMethod("DrawElements") || callStack.FindMethod("DrawArrays");
257
258   bool drawPassed = false;
259   if( testDrawn )
260   {
261     drawPassed = drawResult;
262   }
263   else
264   {
265     drawPassed = !drawResult;
266   }
267
268   bool keepUpdating = (application.GetUpdateStatus() != 0);
269   bool keepUpdatingPassed = false;
270   if( testKeepUpdating )
271   {
272     keepUpdatingPassed = keepUpdating;
273   }
274   else
275   {
276     keepUpdatingPassed = !keepUpdating;
277   }
278
279   bool result = (sigPassed && drawPassed && keepUpdatingPassed);
280
281   tet_printf("UpdateRender: Expected: Draw:%s Signal:%s KeepUpdating: %s  Actual: Draw:%s  Signal:%s KeepUpdating: %s  %s, line %d\n",
282              BOOLSTR(testDrawn), BOOLSTR(testFinished), BOOLSTR(testKeepUpdating),
283              BOOLSTR(drawResult), BOOLSTR(finishedSig), BOOLSTR(keepUpdating),
284              result ? "Passed":"Failed",
285              lineNumber );
286
287   return result;
288 }
289
290 // The functor to be used in the hit-test algorithm to check whether the actor is hittable.
291 bool IsActorHittableFunction(Actor actor, Dali::HitTestAlgorithm::TraverseType type)
292 {
293   bool hittable = false;
294
295   switch (type)
296   {
297     case Dali::HitTestAlgorithm::CHECK_ACTOR:
298     {
299       // Check whether the actor is visible and not fully transparent.
300       if( actor.IsVisible()
301           && actor.GetCurrentWorldColor().a > 0.01f) // not FULLY_TRANSPARENT
302       {
303
304         hittable = true;
305       }
306       break;
307     }
308     case Dali::HitTestAlgorithm::DESCEND_ACTOR_TREE:
309     {
310       if( actor.IsVisible() ) // Actor is visible, if not visible then none of its children are visible.
311       {
312         hittable = true;
313       }
314       break;
315     }
316     default:
317     {
318       break;
319     }
320   }
321
322   return hittable;
323 }
324
325 } // unnamed namespace
326
327
328 /****************************************************************************************************/
329 /****************************************************************************************************/
330 /********************************   TEST CASES BELOW   **********************************************/
331 /****************************************************************************************************/
332 /****************************************************************************************************/
333
334 int UtcDaliRenderTaskDownCast01(void)
335 {
336   TestApplication application;
337
338   tet_infoline("Testing RenderTask::DownCast()");
339
340   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
341
342   BaseHandle base = taskList.GetTask( 0u );
343   DALI_TEST_CHECK( base );
344
345   RenderTask task = RenderTask::DownCast( base );
346   DALI_TEST_CHECK( task );
347
348   // Try calling a method
349   DALI_TEST_CHECK( task.GetSourceActor() );
350   END_TEST;
351 }
352
353 int UtcDaliRenderTaskDownCast02(void)
354 {
355   TestApplication application;
356
357   tet_infoline("Testing RenderTask::DownCast()");
358
359   Actor actor = Actor::New();
360
361   RenderTask task = RenderTask::DownCast( actor );
362   DALI_TEST_CHECK( ! task );
363
364   END_TEST;
365 }
366
367 int UtcDaliRenderTaskSetSourceActorN(void)
368 {
369   TestApplication application;
370   tet_infoline("Testing RenderTask::SetSourceActor() Negative - try with empty actor handle");
371   Stage stage = Stage::GetCurrent();
372
373   Actor srcActor;
374
375   RenderTaskList taskList = stage.GetRenderTaskList();
376   RenderTask renderTask = taskList.CreateTask();
377   renderTask.SetSourceActor(srcActor);
378
379   application.SendNotification();
380   application.Render();
381
382   DALI_TEST_CHECK( ! renderTask.GetSourceActor() );
383   END_TEST;
384 }
385
386
387 int UtcDaliRenderTaskSetSourceActorP01(void)
388 {
389   TestApplication application;
390
391   tet_infoline("Testing RenderTask::SetSourceActor() Positive - check that setting a non-renderable actor stops existing source actor being rendered ");
392
393   Stage stage = Stage::GetCurrent();
394   RenderTaskList taskList = stage.GetRenderTaskList();
395   RenderTask task = taskList.GetTask( 0u );
396
397   Actor actor = task.GetSourceActor();
398   DALI_TEST_CHECK( actor );
399
400   BufferImage img = BufferImage::New( 1,1 );
401   Actor newActor = CreateRenderableActor( img );
402   newActor.SetSize(1,1);
403   stage.Add( newActor );
404
405   Actor nonRenderableActor = Actor::New();
406   stage.Add( nonRenderableActor );
407
408   // Stop the newActor from being rendered by changing the source actor
409   DALI_TEST_CHECK( nonRenderableActor );
410   task.SetSourceActor( nonRenderableActor );
411   DALI_TEST_CHECK( task.GetSourceActor() != actor );
412   DALI_TEST_CHECK( task.GetSourceActor() == nonRenderableActor );
413
414   TestGlAbstraction& gl = application.GetGlAbstraction();
415   TraceCallStack& drawTrace = gl.GetDrawTrace();
416   drawTrace.Enable(true);
417
418   // Update & Render nothing!
419   application.GetGlAbstraction().ClearBoundTextures();
420   application.SendNotification();
421   application.Render();
422
423   // Check that nothing was rendered
424   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 0, TEST_LOCATION );
425
426   END_TEST;
427 }
428
429
430 int UtcDaliRenderTaskSetSourceActorP02(void)
431 {
432   TestApplication application;
433
434   tet_infoline("Testing RenderTask::SetSourceActor() Positive - check that switching source from a non-renderable to a renderable actor causes the texture to be drawn");
435
436   Stage stage = Stage::GetCurrent();
437
438   RenderTaskList taskList = stage.GetRenderTaskList();
439
440   RenderTask task = taskList.GetTask( 0u );
441
442   Actor actor = task.GetSourceActor();
443   DALI_TEST_CHECK( actor );
444
445
446   BufferImage img = BufferImage::New( 1,1 );
447   Actor newActor = CreateRenderableActor( img );
448   newActor.SetSize(1,1);
449   stage.Add( newActor );
450
451   Actor nonRenderableActor = Actor::New();
452   stage.Add( nonRenderableActor );
453
454   TestGlAbstraction& gl = application.GetGlAbstraction();
455   TraceCallStack& drawTrace = gl.GetDrawTrace();
456   drawTrace.Enable(true);
457
458   // Stop the newActor from being rendered by changing the source actor
459   DALI_TEST_CHECK( nonRenderableActor );
460   task.SetSourceActor( nonRenderableActor );
461   DALI_TEST_CHECK( task.GetSourceActor() != actor );
462   DALI_TEST_CHECK( task.GetSourceActor() == nonRenderableActor );
463
464   // Update & Render nothing!
465   application.GetGlAbstraction().ClearBoundTextures();
466   application.SendNotification();
467   application.Render();
468
469   // Check that nothing was rendered
470   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 0, TEST_LOCATION );
471   drawTrace.Reset();
472
473   // Set newActor as the new source Actor
474   task.SetSourceActor( newActor );
475   DALI_TEST_CHECK( task.GetSourceActor() != actor );
476   DALI_TEST_CHECK( task.GetSourceActor() == newActor );
477
478   // Update & Render the newActor
479   application.GetGlAbstraction().ClearBoundTextures();
480   application.SendNotification();
481   application.Render();
482
483   // Check that the newActor was rendered
484   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION );
485   END_TEST;
486 }
487
488 int UtcDaliRenderTaskSetSourceActorOffStage(void)
489 {
490   TestApplication application;
491
492   tet_infoline("Testing RenderTask::SetSourceActor (on/off stage testing)");
493
494   Stage stage = Stage::GetCurrent();
495   RenderTaskList taskList = stage.GetRenderTaskList();
496   RenderTask task = taskList.GetTask( 0u );
497
498   Actor actor = task.GetSourceActor();
499   DALI_TEST_CHECK( actor );
500
501   TestGlAbstraction& gl = application.GetGlAbstraction();
502   TraceCallStack& drawTrace = gl.GetDrawTrace();
503   drawTrace.Enable(true);
504
505   BufferImage img = BufferImage::New( 1,1 );
506   Actor newActor = CreateRenderableActor( img );
507   newActor.SetSize(1,1);
508   task.SetSourceActor( newActor );
509   // Don't add newActor to stage yet   //'
510
511   // Update & Render with the actor initially off-stage
512   application.SendNotification();
513   application.Render();
514
515   // Check that nothing was rendered
516   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 0, TEST_LOCATION );
517
518   // Now add to stage
519   stage.Add( newActor );
520
521   // Update & Render with the actor on-stage
522   application.GetGlAbstraction().ClearBoundTextures();
523   application.SendNotification();
524   application.Render();
525
526   // Check that the newActor was rendered
527   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION );
528   drawTrace.Reset();
529
530   // Now remove from stage
531   stage.Remove( newActor );
532
533   // Update & Render with the actor off-stage
534   application.SendNotification();
535   application.Render();
536   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 0, TEST_LOCATION );
537
538   END_TEST;
539 }
540
541 int UtcDaliRenderTaskSetSourceActorEmpty(void)
542 {
543   TestApplication application;
544
545   tet_infoline("Testing RenderTask::SetSourceActor (empty handle case)");
546
547   Stage stage = Stage::GetCurrent();
548   RenderTaskList taskList = stage.GetRenderTaskList();
549   RenderTask task = taskList.GetTask( 0u );
550
551   Actor actor = task.GetSourceActor();
552   DALI_TEST_CHECK( actor );
553
554   BufferImage img = BufferImage::New( 1,1 );
555   Actor newActor = CreateRenderableActor( img );
556   newActor.SetSize(1,1);
557   stage.Add( newActor );
558
559   Actor nonRenderableActor = Actor::New();
560   stage.Add( nonRenderableActor );
561
562   // Set with empty handle
563   task.SetSourceActor( Actor() );
564   DALI_TEST_CHECK( ! task.GetSourceActor() );
565
566   TestGlAbstraction& gl = application.GetGlAbstraction();
567   TraceCallStack& drawTrace = gl.GetDrawTrace();
568   drawTrace.Enable(true);
569
570   // Update & Render nothing!
571   application.SendNotification();
572   application.Render();
573
574   // Check that nothing was rendered
575   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 0, TEST_LOCATION );
576
577   // Set with non-empty handle
578   task.SetSourceActor( newActor );
579   DALI_TEST_CHECK( task.GetSourceActor() == newActor );
580
581   // Update & Render the newActor
582   application.GetGlAbstraction().ClearBoundTextures();
583   application.SendNotification();
584   application.Render();
585
586   // Check that the newActor was rendered
587   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION );
588   END_TEST;
589 }
590
591 int UtcDaliRenderTaskGetSourceActorP01(void)
592 {
593   TestApplication application;
594
595   tet_infoline("Testing RenderTask::GetSourceActor() Check the default render task has a valid source actor");
596
597   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
598
599   RenderTask task = taskList.GetTask( 0u );
600
601   Actor actor = task.GetSourceActor();
602   DALI_TEST_CHECK( actor );
603
604   // By default the entire scene should be rendered
605   Actor root = Stage::GetCurrent().GetLayer( 0 );
606   DALI_TEST_CHECK( root == actor );
607   END_TEST;
608 }
609
610 int UtcDaliRenderTaskGetSourceActorP02(void)
611 {
612   TestApplication application;
613
614   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.");
615
616   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
617   RenderTask task = taskList.CreateTask();
618   Actor actor = Actor::New();
619   Stage::GetCurrent().Add(actor);
620   task.SetSourceActor( actor );
621
622   DALI_TEST_EQUALS( actor, task.GetSourceActor(), TEST_LOCATION );
623
624   END_TEST;
625 }
626
627 int UtcDaliRenderTaskGetSourceActorN(void)
628 {
629   TestApplication application;
630
631   tet_infoline("Testing RenderTask::GetSourceActor() Try with empty handle");
632
633   RenderTask task;
634   try
635   {
636     Actor actor = task.GetSourceActor();
637   }
638   catch (Dali::DaliException& e)
639   {
640     DALI_TEST_PRINT_ASSERT( e );
641     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
642   }
643
644   END_TEST;
645 }
646
647 int UtcDaliRenderTaskSetExclusive(void)
648 {
649   TestApplication application;
650
651   tet_infoline("Testing RenderTask::SetExclusive() Check that exclusion works");
652
653   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
654
655   // Manipulate the GenTextures behaviour, to identify different actors
656
657   std::vector<GLuint> ids;
658   ids.push_back( 8 ); // 8 = actor1
659   ids.push_back( 9 ); // 9 = actor2
660   ids.push_back( 10 ); // 10 = actor3
661   application.GetGlAbstraction().SetNextTextureIds( ids );
662
663   BufferImage img1 = BufferImage::New( 1,1 );
664   Actor actor1 = CreateRenderableActor( img1 );
665   actor1.SetSize(1,1);
666   Stage::GetCurrent().Add( actor1 );
667
668   // Update & Render actor1
669   application.SendNotification();
670   application.Render();
671
672   // Check that the actor1 was rendered
673   const std::vector<GLuint>& boundTextures = application.GetGlAbstraction().GetBoundTextures( GL_TEXTURE0 );
674   DALI_TEST_EQUALS( boundTextures.size(), 1u, TEST_LOCATION );
675
676   if ( boundTextures.size() )
677   {
678     DALI_TEST_EQUALS( boundTextures[0], 8u/*unique to actor1*/, TEST_LOCATION );
679   }
680
681   BufferImage img2 = BufferImage::New( 1,1 );
682   Actor actor2 = CreateRenderableActor( img2 );
683   actor2.SetSize(1,1);
684
685   // Force actor2 to be rendered before actor1
686   Layer layer = Layer::New();
687   Stage::GetCurrent().Add( layer );
688   layer.Add( actor2 );
689   layer.LowerToBottom();
690
691   // Update & Render
692   application.GetGlAbstraction().ClearBoundTextures();
693   application.SendNotification();
694   application.Render();
695
696   // Check that the actors were rendered
697   DALI_TEST_EQUALS( boundTextures.size(), 2u, TEST_LOCATION );
698
699   if ( boundTextures.size() )
700   {
701     DALI_TEST_EQUALS( boundTextures[0], 9u/*unique to actor2*/, TEST_LOCATION );
702     DALI_TEST_EQUALS( boundTextures[1], 8u/*unique to actor1*/, TEST_LOCATION );
703   }
704
705   BufferImage img3 = BufferImage::New( 1,1 );
706   Actor actor3 = CreateRenderableActor( img3 );
707   actor3.SetSize(1,1);
708
709   // Force actor3 to be rendered before actor2
710   layer = Layer::New();
711   Stage::GetCurrent().Add( layer );
712   layer.Add( actor3 );
713   layer.LowerToBottom();
714
715   // Update & Render all actors
716   application.GetGlAbstraction().ClearBoundTextures();
717   application.SendNotification();
718   application.Render();
719
720   // Check that the actors were rendered
721   DALI_TEST_EQUALS( boundTextures.size(), 3u, TEST_LOCATION );
722
723   if ( boundTextures.size() )
724   {
725     DALI_TEST_EQUALS( boundTextures[0], 10u/*unique to actor3*/, TEST_LOCATION );
726     DALI_TEST_EQUALS( boundTextures[1], 9u/*unique to actor2*/, TEST_LOCATION );
727     DALI_TEST_EQUALS( boundTextures[2], 8u/*unique to actor1*/, TEST_LOCATION );
728   }
729
730   // Both actors are now connected to the root node
731   // Setup 2 render-tasks - the first will render from the root-node, and the second from actor2
732
733   // Not exclusive is the default
734   RenderTask task1 = taskList.GetTask( 0u );
735   DALI_TEST_CHECK( false == task1.IsExclusive() );
736
737   RenderTask task2 = taskList.CreateTask();
738   DALI_TEST_CHECK( false == task2.IsExclusive() );
739   task2.SetSourceActor( actor2 );
740
741   // Task1 should render all actors, and task 2 should render only actor2
742
743   application.GetGlAbstraction().ClearBoundTextures();
744   application.SendNotification();
745   application.Render();
746
747   DALI_TEST_EQUALS( boundTextures.size(), 4u, TEST_LOCATION );
748
749   if ( boundTextures.size() == 4 )
750   {
751     // Test that task 1 renders actor3, then actor2 & then actor1
752     DALI_TEST_CHECK( boundTextures[0] == 10u );
753     DALI_TEST_CHECK( boundTextures[1] == 9u );
754     DALI_TEST_CHECK( boundTextures[2] == 8u );
755
756     // Test that task 2 renders actor2
757     DALI_TEST_EQUALS( boundTextures[3], 9u, TEST_LOCATION );
758   }
759
760   // Make actor2 exclusive to task2
761
762   task2.SetExclusive( true );
763   DALI_TEST_CHECK( true == task2.IsExclusive() );
764
765   // Task1 should render only actor1, and task 2 should render only actor2
766
767   application.GetGlAbstraction().ClearBoundTextures();
768   application.SendNotification();
769   application.Render();
770
771   DALI_TEST_EQUALS( boundTextures.size(), 3u, TEST_LOCATION );
772   if ( boundTextures.size() == 3 )
773   {
774     // Test that task 1 renders actor3 & actor1
775     DALI_TEST_CHECK( boundTextures[0] == 10u );
776     DALI_TEST_CHECK( boundTextures[1] == 8u );
777
778     // Test that task 2 renders actor2
779     DALI_TEST_CHECK( boundTextures[2] == 9u );
780   }
781   END_TEST;
782 }
783
784 int UtcDaliRenderTaskSetExclusive02(void)
785 {
786   TestApplication application;
787
788   tet_infoline("Testing RenderTask::SetExclusive() Check that changing from exclusive to not-exclusive works");
789
790   std::vector<GLuint> ids;
791   ids.push_back( 8 ); // 8 = actor1
792   application.GetGlAbstraction().SetNextTextureIds( ids );
793
794   BufferImage img1 = BufferImage::New( 1,1 );
795   Actor actor1 = CreateRenderableActor( img1 );
796   actor1.SetSize(1,1);
797   Stage::GetCurrent().Add( actor1 );
798
799   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
800   RenderTask task = taskList.CreateTask();
801
802   task.SetSourceActor( actor1 );
803   task.SetExclusive(true); // Actor should only render once
804
805   TestGlAbstraction& gl = application.GetGlAbstraction();
806   TraceCallStack& drawTrace = gl.GetDrawTrace();
807   drawTrace.Enable(true);
808
809   // Update & Render actor1
810   application.SendNotification();
811   application.Render();
812
813   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION );
814
815   // Set task to non-exclusive - actor1 should render twice:
816   drawTrace.Reset();
817   task.SetExclusive(false);
818   application.SendNotification();
819   application.Render();
820
821   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 2, TEST_LOCATION );
822
823   END_TEST;
824 }
825
826 int UtcDaliRenderTaskSetExclusiveN(void)
827 {
828   TestApplication application;
829
830   tet_infoline("Testing RenderTask::SetExclusive() on empty handle");
831
832   RenderTask task;
833   try
834   {
835     task.SetExclusive(true);
836   }
837   catch (Dali::DaliException& e)
838   {
839     DALI_TEST_PRINT_ASSERT( e );
840     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
841   }
842   END_TEST;
843 }
844
845 int UtcDaliRenderTaskIsExclusive01(void)
846 {
847   TestApplication application;
848
849   tet_infoline("Testing RenderTask::IsExclusive() Check default values are non-exclusive");
850
851   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
852
853   // Not exclusive is the default
854   RenderTask task = taskList.GetTask( 0u );
855   DALI_TEST_CHECK( false == task.IsExclusive() );
856
857   RenderTask newTask = taskList.CreateTask();
858   DALI_TEST_CHECK( false == newTask.IsExclusive() );
859
860   END_TEST;
861 }
862
863 int UtcDaliRenderTaskIsExclusive02(void)
864 {
865   TestApplication application;
866
867   tet_infoline("Testing RenderTask::IsExclusive() Check the getter returns set values");
868
869   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
870
871   // Not exclusive is the default
872   RenderTask newTask = taskList.CreateTask();
873   DALI_TEST_EQUALS( newTask.IsExclusive(), false, TEST_LOCATION );
874
875   newTask.SetExclusive(true);
876   DALI_TEST_EQUALS( newTask.IsExclusive(), true, TEST_LOCATION );
877   END_TEST;
878 }
879
880 int UtcDaliRenderTaskIsExclusiveN(void)
881 {
882   TestApplication application;
883
884   tet_infoline("Testing RenderTask::IsExclusive() on empty handle");
885
886   RenderTask task;
887   try
888   {
889     bool x = task.IsExclusive();
890     (void) x;
891   }
892   catch (Dali::DaliException& e)
893   {
894     DALI_TEST_PRINT_ASSERT( e );
895     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
896   }
897   END_TEST;
898 }
899
900 int UtcDaliRenderTaskSetInputEnabled(void)
901 {
902   TestApplication application;
903
904   tet_infoline("Testing RenderTask::SetInputEnabled()");
905
906   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
907
908   // Input is enabled by default
909   RenderTask task = taskList.GetTask( 0u );
910   DALI_TEST_CHECK( true == task.GetInputEnabled() );
911
912   task.SetInputEnabled( false );
913   DALI_TEST_CHECK( false == task.GetInputEnabled() );
914
915   task.SetInputEnabled( true );
916   DALI_TEST_CHECK( true == task.GetInputEnabled() );
917   END_TEST;
918 }
919
920 int UtcDaliRenderTaskGetInputEnabled(void)
921 {
922   TestApplication application;
923
924   tet_infoline("Testing RenderTask::GetInputEnabled()");
925
926   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
927
928   // Input is enabled by default
929   RenderTask task = taskList.GetTask( 0u );
930   DALI_TEST_EQUALS( true, task.GetInputEnabled(), TEST_LOCATION );
931
932   RenderTask newTask = taskList.CreateTask();
933   DALI_TEST_EQUALS( true, newTask.GetInputEnabled(), TEST_LOCATION );
934
935   newTask.SetInputEnabled(false);
936   DALI_TEST_EQUALS( false, newTask.GetInputEnabled(), TEST_LOCATION );
937
938   END_TEST;
939 }
940
941 int UtcDaliRenderTaskSetCameraActorP(void)
942 {
943   TestApplication application;
944
945   tet_infoline("Testing RenderTask::SetCameraActor()");
946
947   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
948
949   RenderTask task = taskList.GetTask( 0u );
950
951   Actor defaultCameraActor = task.GetCameraActor();
952   DALI_TEST_CHECK( defaultCameraActor );
953
954   CameraActor newCameraActor = CameraActor::New();
955   DALI_TEST_CHECK( newCameraActor );
956
957   task.SetCameraActor( newCameraActor );
958   DALI_TEST_CHECK( task.GetCameraActor() != defaultCameraActor );
959   DALI_TEST_EQUALS( task.GetCameraActor(), newCameraActor, TEST_LOCATION );
960   END_TEST;
961 }
962
963
964 int UtcDaliRenderTaskSetCameraActorN(void)
965 {
966   TestApplication application;
967
968   tet_infoline("Testing RenderTask::SetCameraActor() with empty actor handle");
969
970   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
971
972   RenderTask task = taskList.GetTask( 0u );
973
974   Actor actor = task.GetCameraActor();
975   DALI_TEST_CHECK( actor );
976
977   CameraActor cameraActor;
978
979   task.SetCameraActor( cameraActor );
980   DALI_TEST_EQUALS( (bool)task.GetCameraActor(), false, TEST_LOCATION );
981   DALI_TEST_EQUALS( task.GetCameraActor(), cameraActor, TEST_LOCATION );
982   END_TEST;
983 }
984
985
986 int UtcDaliRenderTaskGetCameraActorP(void)
987 {
988   TestApplication application;
989
990   tet_infoline("Testing RenderTask::GetCameraActor()");
991
992   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
993
994   RenderTask task = taskList.GetTask( 0u );
995
996   CameraActor actor = task.GetCameraActor();
997   DALI_TEST_CHECK( actor );
998   DALI_TEST_EQUALS( actor.GetProjectionMode(), Dali::Camera::PERSPECTIVE_PROJECTION, TEST_LOCATION );
999   DALI_TEST_GREATER( actor.GetFieldOfView(), 0.0f, TEST_LOCATION );
1000   END_TEST;
1001 }
1002
1003 int UtcDaliRenderTaskGetCameraActorN(void)
1004 {
1005   TestApplication application;
1006
1007   tet_infoline("Testing RenderTask::GetCameraActor() with empty handle");
1008   RenderTask task;
1009
1010   try
1011   {
1012     Actor actor = task.GetCameraActor();
1013   }
1014   catch (Dali::DaliException& e)
1015   {
1016     DALI_TEST_PRINT_ASSERT( e );
1017     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1018   }
1019
1020   END_TEST;
1021 }
1022
1023 int UtcDaliRenderTaskSetTargetFrameBufferP(void)
1024 {
1025   TestApplication application;
1026
1027   tet_infoline("Testing RenderTask::SetTargetFrameBuffer()");
1028
1029   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1030
1031   RenderTask task = taskList.GetTask( 0u );
1032
1033   FrameBufferImage newImage = FrameBufferImage::New();
1034   task.SetTargetFrameBuffer( newImage );
1035   DALI_TEST_CHECK( task.GetTargetFrameBuffer() == newImage );
1036   END_TEST;
1037 }
1038
1039 int UtcDaliRenderTaskSetTargetFrameBufferN(void)
1040 {
1041   TestApplication application;
1042
1043   tet_infoline("Testing RenderTask::SetTargetFrameBuffer()");
1044
1045   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1046
1047   RenderTask task = taskList.GetTask( 0u );
1048   FrameBufferImage newImage; // Empty handle
1049   task.SetTargetFrameBuffer( newImage );
1050   DALI_TEST_EQUALS( (bool)task.GetTargetFrameBuffer(), false, TEST_LOCATION );
1051   END_TEST;
1052 }
1053
1054 int UtcDaliRenderTaskGetTargetFrameBufferP(void)
1055 {
1056   TestApplication application;
1057
1058   tet_infoline("Testing RenderTask::GetTargetFrameBuffer()");
1059
1060   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1061
1062   RenderTask newTask = taskList.CreateTask();
1063   FrameBufferImage fb = FrameBufferImage::New(128, 128, Pixel::RGBA8888);
1064   newTask.SetTargetFrameBuffer( fb );
1065   DALI_TEST_EQUALS( newTask.GetTargetFrameBuffer(), fb, TEST_LOCATION );
1066   END_TEST;
1067 }
1068
1069 int UtcDaliRenderTaskGetTargetFrameBufferN(void)
1070 {
1071   TestApplication application;
1072
1073   tet_infoline("Testing RenderTask::GetTargetFrameBuffer()");
1074
1075   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1076
1077   RenderTask task = taskList.GetTask( 0u );
1078
1079   // By default render-tasks do not render off-screen
1080   FrameBufferImage image = task.GetTargetFrameBuffer();
1081   DALI_TEST_CHECK( !image );
1082
1083   END_TEST;
1084 }
1085
1086 int UtcDaliRenderTaskSetFrameBufferP(void)
1087 {
1088   TestApplication application;
1089
1090   tet_infoline("Testing RenderTask::SetFrameBuffer()");
1091
1092   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1093
1094   RenderTask task = taskList.GetTask( 0u );
1095
1096   FrameBuffer newFrameBuffer = FrameBuffer::New( 128u, 128u, FrameBuffer::Attachment::NONE );
1097   task.SetFrameBuffer( newFrameBuffer );
1098   DALI_TEST_CHECK( task.GetFrameBuffer() == newFrameBuffer );
1099   END_TEST;
1100 }
1101
1102 int UtcDaliRenderTaskSetFrameBufferN(void)
1103 {
1104   TestApplication application;
1105
1106   tet_infoline("Testing RenderTask::SetFrameBuffer()");
1107
1108   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1109
1110   RenderTask task = taskList.GetTask( 0u );
1111   FrameBuffer newFrameBuffer; // Empty handle
1112   task.SetFrameBuffer( newFrameBuffer );
1113   DALI_TEST_EQUALS( (bool)task.GetFrameBuffer(), false, TEST_LOCATION );
1114   END_TEST;
1115 }
1116
1117 int UtcDaliRenderTaskGetFrameBufferP(void)
1118 {
1119   TestApplication application;
1120
1121   tet_infoline("Testing RenderTask::GetFrameBuffer()");
1122
1123   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1124
1125   RenderTask task = taskList.GetTask( 0u );
1126
1127   FrameBuffer newFrameBuffer = FrameBuffer::New( 1u, 1u, FrameBuffer::Attachment::NONE  );
1128   task.SetFrameBuffer( newFrameBuffer );
1129   DALI_TEST_CHECK( task.GetFrameBuffer() == newFrameBuffer );
1130   END_TEST;
1131 }
1132
1133 int UtcDaliRenderTaskGetFrameBufferN(void)
1134 {
1135   TestApplication application;
1136
1137   tet_infoline("Testing RenderTask::GetFrameBuffer()");
1138
1139   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1140
1141   RenderTask task = taskList.GetTask( 0u );
1142
1143   // By default render-tasks do not render off-screen
1144   FrameBuffer frameBuffer = task.GetFrameBuffer();
1145   DALI_TEST_CHECK( !frameBuffer );
1146
1147   END_TEST;
1148 }
1149
1150 int UtcDaliRenderTaskSetScreenToFrameBufferFunctionP(void)
1151 {
1152   TestApplication application;
1153
1154   tet_infoline("Testing RenderTask::SetScreenToFrameBufferFunction()");
1155
1156   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1157
1158   RenderTask task = taskList.GetTask( 0u );
1159
1160   task.SetScreenToFrameBufferFunction( TestScreenToFrameBufferFunction );
1161
1162   Vector2 coordinates( 5, 10 );
1163   Vector2 convertedCoordinates( 6, 12 ); // + Vector(1, 2)
1164
1165   RenderTask::ScreenToFrameBufferFunction func = task.GetScreenToFrameBufferFunction();
1166   DALI_TEST_CHECK( func( coordinates ) );
1167   DALI_TEST_CHECK( coordinates == convertedCoordinates );
1168
1169   task.SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );
1170   func = task.GetScreenToFrameBufferFunction();
1171   DALI_TEST_CHECK( func( coordinates ) );
1172
1173   task.SetScreenToFrameBufferFunction( RenderTask::DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION );
1174   func = task.GetScreenToFrameBufferFunction();
1175   DALI_TEST_CHECK( ! func( coordinates ) );
1176   END_TEST;
1177 }
1178
1179 int UtcDaliRenderTaskSetScreenToFrameBufferFunctionN(void)
1180 {
1181   TestApplication application;
1182
1183   tet_infoline("Testing RenderTask::SetScreenToFrameBufferFunction()");
1184
1185   RenderTask task; // Empty handle
1186   try
1187   {
1188     task.SetScreenToFrameBufferFunction( TestScreenToFrameBufferFunction );
1189   }
1190   catch (Dali::DaliException& e)
1191   {
1192     DALI_TEST_PRINT_ASSERT( e );
1193     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1194   }
1195   END_TEST;
1196 }
1197
1198 int UtcDaliRenderTaskGetScreenToFrameBufferFunctionP(void)
1199 {
1200   TestApplication application;
1201
1202   tet_infoline("Testing RenderTask::GetScreenToFrameBufferFunction()");
1203
1204   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1205
1206   RenderTask task = taskList.GetTask( 0u );
1207
1208   Vector2 originalCoordinates( 5, 10 );
1209   Vector2 coordinates( 5, 10 );
1210
1211   RenderTask::ScreenToFrameBufferFunction func = task.GetScreenToFrameBufferFunction();
1212   DALI_TEST_CHECK( !func( coordinates ) ); // conversion should fail by default
1213   DALI_TEST_CHECK( coordinates == originalCoordinates ); // coordinates should not be modified
1214   END_TEST;
1215 }
1216
1217 int UtcDaliRenderTaskGetScreenToFrameBufferFunctionN(void)
1218 {
1219   TestApplication application;
1220
1221   tet_infoline("Testing RenderTask::GetScreenToFrameBufferFunction() on empty handle");
1222
1223   RenderTask task;
1224   try
1225   {
1226     RenderTask::ScreenToFrameBufferFunction func = task.GetScreenToFrameBufferFunction();
1227     (void) func;
1228   }
1229   catch (Dali::DaliException& e)
1230   {
1231     DALI_TEST_PRINT_ASSERT( e );
1232     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1233   }
1234   END_TEST;
1235 }
1236
1237
1238 int UtcDaliRenderTaskGetScreenToFrameBufferMappingActorP(void)
1239 {
1240   TestApplication application;
1241   tet_infoline("Testing RenderTask::GetScreenToFrameBufferMappingActor ");
1242
1243   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1244   RenderTask renderTask = taskList.CreateTask();
1245   Actor mappingActor = Actor::New();
1246   renderTask.SetScreenToFrameBufferMappingActor(mappingActor);
1247
1248   DALI_TEST_EQUALS( mappingActor, renderTask.GetScreenToFrameBufferMappingActor(), TEST_LOCATION );
1249   END_TEST;
1250 }
1251
1252
1253 int UtcDaliRenderTaskGetScreenToFrameBufferMappingActorN(void)
1254 {
1255   TestApplication application;
1256   tet_infoline("Testing RenderTask::GetScreenToFrameBufferMappingActor with empty task handle");
1257
1258   RenderTask task;
1259   try
1260   {
1261     Actor mappingActor;
1262     task.SetScreenToFrameBufferMappingActor(mappingActor);
1263   }
1264   catch (Dali::DaliException& e)
1265   {
1266     DALI_TEST_PRINT_ASSERT( e );
1267     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1268   }
1269   END_TEST;
1270 }
1271
1272 int UtcDaliRenderTaskGetScreenToFrameBufferMappingActor02N(void)
1273 {
1274   TestApplication application;
1275   tet_infoline("Testing RenderTask::GetScreenToFrameBufferMappingActor with empty task handle");
1276
1277   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1278   RenderTask renderTask = taskList.CreateTask();
1279   Actor actor;
1280   renderTask.SetScreenToFrameBufferMappingActor(actor);
1281
1282   DALI_TEST_EQUALS( (bool)renderTask.GetScreenToFrameBufferMappingActor(), false, TEST_LOCATION);
1283   END_TEST;
1284 }
1285
1286 int UtcDaliRenderTaskGetViewportP01(void)
1287 {
1288   TestApplication application;
1289
1290   tet_infoline("Testing RenderTask::GetViewport() on default task");
1291
1292   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1293   RenderTask task = taskList.GetTask( 0u );
1294   Viewport viewport = task.GetViewport();
1295
1296   // By default the viewport should match the stage width/height
1297   Vector2 stageSize = Stage::GetCurrent().GetSize();
1298   Viewport expectedViewport( 0, 0, stageSize.width, stageSize.height );
1299   DALI_TEST_CHECK( viewport == expectedViewport );
1300   END_TEST;
1301 }
1302
1303 int UtcDaliRenderTaskGetViewportP02(void)
1304 {
1305   TestApplication application;
1306
1307   tet_infoline("Testing RenderTask::GetViewport() on new task");
1308
1309   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1310   RenderTask task = taskList.CreateTask();
1311   Viewport viewport = task.GetViewport();
1312
1313   // By default the viewport should match the stage width/height
1314   Vector2 stageSize = Stage::GetCurrent().GetSize();
1315   Viewport expectedViewport( 0, 0, stageSize.width, stageSize.height );
1316   DALI_TEST_CHECK( viewport == expectedViewport );
1317   END_TEST;
1318 }
1319
1320 int UtcDaliRenderTaskGetViewportN(void)
1321 {
1322   TestApplication application;
1323
1324   tet_infoline("Testing RenderTask::GetViewport() on empty handle");
1325
1326   RenderTask task;
1327   try
1328   {
1329     Viewport viewport = task.GetViewport();
1330     (void) viewport;
1331   }
1332   catch (Dali::DaliException& e)
1333   {
1334     DALI_TEST_PRINT_ASSERT( e );
1335     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1336   }
1337   END_TEST;
1338 }
1339
1340
1341 int UtcDaliRenderTaskSetViewportP(void)
1342 {
1343   TestApplication application;
1344
1345   tet_infoline("Testing RenderTask::SetViewport()");
1346
1347   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1348
1349   RenderTask task = taskList.GetTask( 0u );
1350   Vector2 stageSize = Stage::GetCurrent().GetSize();
1351   Viewport newViewport( 0, 0, stageSize.width * 0.5f, stageSize.height * 0.5f );
1352   task.SetViewport( newViewport );
1353
1354   // Update (viewport is a property)
1355   application.SendNotification();
1356   application.Render();
1357
1358   DALI_TEST_CHECK( task.GetViewport() == newViewport );
1359   END_TEST;
1360 }
1361
1362 int UtcDaliRenderTaskSetViewportN(void)
1363 {
1364   TestApplication application;
1365
1366   tet_infoline("Testing RenderTask::SetViewport()");
1367
1368   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1369
1370   RenderTask task;
1371   try
1372   {
1373     Vector2 stageSize = Stage::GetCurrent().GetSize();
1374     Viewport newViewport( 0, 0, stageSize.width * 0.5f, stageSize.height * 0.5f );
1375     task.SetViewport( newViewport );
1376   }
1377   catch (Dali::DaliException& e)
1378   {
1379     DALI_TEST_PRINT_ASSERT( e );
1380     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1381   }
1382
1383   END_TEST;
1384 }
1385
1386
1387 int UtcDaliRenderTaskSetViewportPosition(void)
1388 {
1389   TestApplication application;
1390
1391   tet_infoline("Testing RenderTask::SetViewportPosition()");
1392
1393   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1394
1395   RenderTask task = taskList.GetTask( 0u );
1396
1397   Viewport viewport = task.GetViewport();
1398
1399   // By default the viewport should match the stage width/height
1400
1401   Vector2 stageSize = Stage::GetCurrent().GetSize();
1402   Viewport expectedViewport( 0, 0, stageSize.width, stageSize.height );
1403   DALI_TEST_CHECK( viewport == expectedViewport );
1404
1405   // 'Setter' test
1406   Vector2 newPosition(25.0f, 50.0f);
1407   task.SetViewportPosition( newPosition );
1408
1409   // Update (viewport is a property)
1410   application.SendNotification();
1411   application.Render();
1412
1413   DALI_TEST_EQUALS( task.GetCurrentViewportPosition(), newPosition, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1414
1415   // Set by Property test
1416   Vector2 newPosition2(32.0f, 32.0f);
1417   task.SetProperty( RenderTask::Property::VIEWPORT_POSITION, newPosition2 );
1418   DALI_TEST_EQUALS( task.GetProperty< Vector2 >( RenderTask::Property::VIEWPORT_POSITION ), newPosition2, TEST_LOCATION );
1419   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector2 >( task, RenderTask::Property::VIEWPORT_POSITION ), newPosition, TEST_LOCATION ); // still the old position
1420
1421   // Update
1422   application.SendNotification();
1423   application.Render();
1424
1425   DALI_TEST_EQUALS( task.GetCurrentViewportPosition(), newPosition2, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1426   DALI_TEST_EQUALS( task.GetProperty< Vector2 >( RenderTask::Property::VIEWPORT_POSITION ), newPosition2, TEST_LOCATION );
1427   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector2 >( task, RenderTask::Property::VIEWPORT_POSITION ), newPosition2, TEST_LOCATION );
1428
1429   Vector2 newPosition3(64.0f, 0.0f);
1430   Animation animation = Animation::New(1.0f);
1431   animation.AnimateTo( Property( task, RenderTask::Property::VIEWPORT_POSITION ), newPosition3, AlphaFunction::LINEAR );
1432   animation.Play();
1433
1434   DALI_TEST_EQUALS( task.GetProperty< Vector2 >( RenderTask::Property::VIEWPORT_POSITION ), newPosition3, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1435   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector2 >( task, RenderTask::Property::VIEWPORT_POSITION ), newPosition2, TEST_LOCATION );
1436
1437   // Perform 1000ms worth of updates at which point animation should have completed.
1438   Wait(application, 1000);
1439   DALI_TEST_EQUALS( task.GetCurrentViewportPosition(), newPosition3, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1440   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector2 >( task, RenderTask::Property::VIEWPORT_POSITION ), newPosition3, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1441   DALI_TEST_EQUALS( task.GetProperty< Vector2 >( RenderTask::Property::VIEWPORT_POSITION ), newPosition3, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1442   END_TEST;
1443 }
1444
1445 int UtcDaliRenderTaskSetViewportSize(void)
1446 {
1447   TestApplication application;
1448
1449   tet_infoline("Testing RenderTask::SetViewportSize()");
1450
1451   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1452
1453   RenderTask task = taskList.GetTask( 0u );
1454
1455   Viewport viewport = task.GetViewport();
1456
1457   // By default the viewport should match the stage width/height
1458
1459   Vector2 stageSize = Stage::GetCurrent().GetSize();
1460   Viewport expectedViewport( 0, 0, stageSize.width, stageSize.height );
1461   DALI_TEST_CHECK( viewport == expectedViewport );
1462
1463   Vector2 newSize(128.0f, 64.0f);
1464   task.SetViewportSize( newSize );
1465
1466   // Update (viewport is a property)
1467   application.SendNotification();
1468   application.Render();
1469
1470   DALI_TEST_EQUALS( task.GetCurrentViewportSize(), newSize, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1471
1472   // Set by Property test
1473   Vector2 newSize2(50.0f, 50.0f);
1474   task.SetProperty( RenderTask::Property::VIEWPORT_SIZE, newSize2 );
1475   DALI_TEST_EQUALS( task.GetProperty< Vector2 >( RenderTask::Property::VIEWPORT_SIZE ), newSize2, TEST_LOCATION );
1476   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector2 >( task, RenderTask::Property::VIEWPORT_SIZE ), newSize, TEST_LOCATION ); // still the old position
1477
1478   // Update
1479   application.SendNotification();
1480   application.Render();
1481
1482   DALI_TEST_EQUALS( task.GetCurrentViewportSize(), newSize2, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1483   DALI_TEST_EQUALS( task.GetProperty< Vector2 >( RenderTask::Property::VIEWPORT_SIZE ), newSize2, TEST_LOCATION );
1484   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector2 >( task, RenderTask::Property::VIEWPORT_SIZE ), newSize2, TEST_LOCATION );
1485
1486   Vector2 newSize3(10.0f, 10.0f);
1487   Animation animation = Animation::New(1.0f);
1488   animation.AnimateTo( Property( task, RenderTask::Property::VIEWPORT_SIZE ), newSize3, AlphaFunction::LINEAR );
1489   animation.Play();
1490
1491   DALI_TEST_EQUALS( task.GetProperty< Vector2 >( RenderTask::Property::VIEWPORT_SIZE  ), newSize3, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1492   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector2 >( task, RenderTask::Property::VIEWPORT_SIZE ), newSize2, TEST_LOCATION );
1493
1494   // Perform 1000ms worth of updates at which point animation should have completed.
1495   Wait(application, 1000);
1496   DALI_TEST_EQUALS( task.GetCurrentViewportSize(), newSize3, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1497   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector2 >( task, RenderTask::Property::VIEWPORT_SIZE ), newSize3, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1498   DALI_TEST_EQUALS( task.GetProperty< Vector2 >( RenderTask::Property::VIEWPORT_SIZE  ), newSize3, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1499
1500   END_TEST;
1501 }
1502
1503 int UtcDaliRenderTaskSetClearColorP(void)
1504 {
1505   TestApplication application;
1506
1507   tet_infoline("Testing RenderTask::SetClearColor()");
1508
1509   Vector4 testColor( 1.0f, 2.0f, 3.0f, 4.0f );
1510   Vector4 testColor2( 5.0f, 6.0f, 7.0f, 8.0f );
1511
1512   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1513
1514   RenderTask task = taskList.GetTask( 0u );
1515   DALI_TEST_CHECK( task.GetClearColor() != testColor );
1516
1517   task.SetClearColor( testColor );
1518
1519   // Wait a frame.
1520   Wait(application);
1521
1522   DALI_TEST_EQUALS( task.GetClearColor(), testColor, TEST_LOCATION );
1523
1524   task.SetProperty( RenderTask::Property::CLEAR_COLOR, testColor2 );
1525   DALI_TEST_EQUALS( task.GetProperty< Vector4 >( RenderTask::Property::CLEAR_COLOR ), testColor2, TEST_LOCATION );
1526   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector4 >( task, RenderTask::Property::CLEAR_COLOR ), testColor, TEST_LOCATION ); // still the old color
1527
1528   // Wait a frame.
1529   Wait(application);
1530
1531   DALI_TEST_EQUALS( task.GetClearColor(), testColor2, TEST_LOCATION );
1532   DALI_TEST_EQUALS( task.GetProperty< Vector4 >( RenderTask::Property::CLEAR_COLOR ), testColor2, TEST_LOCATION );
1533   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector4 >( task, RenderTask::Property::CLEAR_COLOR ), testColor2, TEST_LOCATION );
1534
1535   Vector4 newColor3(10.0f, 10.0f, 20.0f, 30.0f);
1536   Animation animation = Animation::New(1.0f);
1537   animation.AnimateTo( Property( task, RenderTask::Property::CLEAR_COLOR ), newColor3, AlphaFunction::LINEAR );
1538   animation.Play();
1539
1540   DALI_TEST_EQUALS( task.GetProperty< Vector4 >( RenderTask::Property::CLEAR_COLOR  ), newColor3, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1541   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector4 >( task, RenderTask::Property::CLEAR_COLOR ), testColor2, TEST_LOCATION );
1542
1543   // Perform 1000ms worth of updates at which point animation should have completed.
1544   Wait(application, 1000);
1545   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector4 >( task, RenderTask::Property::CLEAR_COLOR ), newColor3, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1546   DALI_TEST_EQUALS( task.GetProperty< Vector4 >( RenderTask::Property::CLEAR_COLOR  ), newColor3, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1547
1548   END_TEST;
1549 }
1550
1551 int UtcDaliRenderTaskSetClearColorN(void)
1552 {
1553   TestApplication application;
1554
1555   tet_infoline("Testing RenderTask::SetClearColor() on empty handle");
1556
1557   RenderTask task;
1558   try
1559   {
1560     task.SetClearColor( Vector4::ZERO );
1561   }
1562   catch (Dali::DaliException& e)
1563   {
1564     DALI_TEST_PRINT_ASSERT( e );
1565     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1566   }
1567   END_TEST;
1568 }
1569
1570 int UtcDaliRenderTaskGetClearColorP(void)
1571 {
1572   TestApplication application;
1573
1574   tet_infoline("Testing RenderTask::GetClearColor()");
1575
1576   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1577   RenderTask task = taskList.GetTask( 0u );
1578   DALI_TEST_EQUALS( task.GetClearColor(), RenderTask::DEFAULT_CLEAR_COLOR, TEST_LOCATION );
1579   END_TEST;
1580 }
1581
1582 int UtcDaliRenderTaskGetClearColorN(void)
1583 {
1584   TestApplication application;
1585
1586   tet_infoline("Testing RenderTask::GetClearColor()");
1587
1588   RenderTask task;
1589   try
1590   {
1591     Vector4 color = task.GetClearColor();
1592     (void) color;
1593   }
1594   catch (Dali::DaliException& e)
1595   {
1596     DALI_TEST_PRINT_ASSERT( e );
1597     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1598   }
1599   END_TEST;
1600 }
1601
1602 int UtcDaliRenderTaskSetClearEnabledP(void)
1603 {
1604   TestApplication application;
1605
1606   tet_infoline("Testing RenderTask::SetClearEnabled()");
1607
1608   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1609
1610   RenderTask task = taskList.GetTask( 0u );
1611   DALI_TEST_CHECK( !task.GetClearEnabled() ); // defaults to false
1612
1613   task.SetClearEnabled( true );
1614   DALI_TEST_EQUALS( task.GetClearEnabled(), true, TEST_LOCATION );
1615
1616   task.SetClearEnabled( false );
1617   DALI_TEST_EQUALS( task.GetClearEnabled(), false, TEST_LOCATION );
1618   END_TEST;
1619 }
1620
1621 int UtcDaliRenderTaskSetClearEnabledN(void)
1622 {
1623   TestApplication application;
1624
1625   tet_infoline("Testing RenderTask::SetClearEnabled() with empty handle");
1626
1627   RenderTask task;
1628   try
1629   {
1630     task.SetClearEnabled(true);
1631   }
1632   catch (Dali::DaliException& e)
1633   {
1634     DALI_TEST_PRINT_ASSERT( e );
1635     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1636   }
1637   END_TEST;
1638 }
1639
1640 int UtcDaliRenderTaskGetClearEnabledP(void)
1641 {
1642   TestApplication application;
1643
1644   tet_infoline("Testing RenderTask::GetClearEnabled()");
1645
1646   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1647
1648   RenderTask task = taskList.GetTask( 0u );
1649   DALI_TEST_CHECK( !task.GetClearEnabled() ); // defaults to false
1650   END_TEST;
1651 }
1652
1653
1654 int UtcDaliRenderTaskGetClearEnabledN(void)
1655 {
1656   TestApplication application;
1657
1658   tet_infoline("Testing RenderTask::GetClearEnabled() with empty handle");
1659
1660   RenderTask task;
1661   try
1662   {
1663     bool x = task.GetClearEnabled();
1664     (void) x;
1665   }
1666   catch (Dali::DaliException& e)
1667   {
1668     DALI_TEST_PRINT_ASSERT( e );
1669     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1670   }
1671   END_TEST;
1672 }
1673
1674 int UtcDaliRenderTaskSetCullModeP(void)
1675 {
1676   TestApplication application;
1677
1678   tet_infoline("Testing RenderTask::SetCullMode()");
1679
1680   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1681   RenderTask task = taskList.GetTask( 0u );
1682   DALI_TEST_EQUALS( task.GetCullMode(), true, TEST_LOCATION );
1683
1684   task.SetCullMode( false );
1685
1686   DALI_TEST_EQUALS( task.GetCullMode(), false, TEST_LOCATION );
1687
1688   END_TEST;
1689 }
1690
1691 int UtcDaliRenderTaskSetCullModeN(void)
1692 {
1693   TestApplication application;
1694
1695   tet_infoline("Testing RenderTask::SetCullMode() on empty handle");
1696
1697   RenderTask task;
1698   try
1699   {
1700     task.SetCullMode( false );
1701   }
1702   catch (Dali::DaliException& e)
1703   {
1704     DALI_TEST_PRINT_ASSERT( e );
1705     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1706   }
1707   END_TEST;
1708 }
1709
1710 int UtcDaliRenderTaskGetCullModeP(void)
1711 {
1712   TestApplication application;
1713
1714   tet_infoline("Testing RenderTask::GetCullMode()");
1715
1716   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1717   RenderTask task = taskList.GetTask( 0u );
1718   DALI_TEST_EQUALS( task.GetCullMode(), true, TEST_LOCATION );
1719   END_TEST;
1720 }
1721
1722 int UtcDaliRenderTaskGetCullModeN(void)
1723 {
1724   TestApplication application;
1725
1726   tet_infoline("Testing RenderTask::GetCullMode() with empty handle");
1727
1728   RenderTask task;
1729   try
1730   {
1731     bool x = task.GetCullMode();
1732     (void) x;
1733   }
1734   catch (Dali::DaliException& e)
1735   {
1736     DALI_TEST_PRINT_ASSERT( e );
1737     DALI_TEST_ASSERT(e, "RenderTask handle is empty", TEST_LOCATION);
1738   }
1739   END_TEST;
1740 }
1741
1742
1743 int UtcDaliRenderTaskSetRefreshRate(void)
1744 {
1745   TestApplication application;
1746
1747   tet_infoline("Testing RenderTask::SetRefreshRate()");
1748
1749   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1750
1751   // By default tasks will be processed every frame
1752   RenderTask task = taskList.GetTask( 0u );
1753   DALI_TEST_CHECK( RenderTask::REFRESH_ALWAYS == task.GetRefreshRate() );
1754
1755   task.SetRefreshRate( 2u ); // every-other frame
1756   DALI_TEST_CHECK( 2u == task.GetRefreshRate() );
1757
1758   task.SetRefreshRate( RenderTask::REFRESH_ALWAYS );
1759   DALI_TEST_CHECK( RenderTask::REFRESH_ALWAYS == task.GetRefreshRate() );
1760   END_TEST;
1761 }
1762
1763 int UtcDaliRenderTaskGetRefreshRate(void)
1764 {
1765   TestApplication application;
1766
1767   tet_infoline("Testing RenderTask::GetRefreshRate()");
1768
1769   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1770
1771   // By default tasks will be processed every frame
1772   RenderTask task = taskList.GetTask( 0u );
1773   DALI_TEST_CHECK( RenderTask::REFRESH_ALWAYS == task.GetRefreshRate() );
1774
1775   RenderTask newTask = taskList.CreateTask();
1776   DALI_TEST_CHECK( RenderTask::REFRESH_ALWAYS == newTask.GetRefreshRate() );
1777   END_TEST;
1778 }
1779
1780 int UtcDaliRenderTaskSignalFinished(void)
1781 {
1782   TestApplication application;
1783
1784   tet_infoline("Testing RenderTask::SignalFinished()");
1785
1786   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1787   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
1788
1789   CameraActor offscreenCameraActor = CameraActor::New();
1790
1791   Stage::GetCurrent().Add( offscreenCameraActor );
1792
1793   BufferImage image = BufferImage::New( 10, 10 );
1794   image.Update();
1795   Actor rootActor = CreateRenderableActor( image );
1796   rootActor.SetSize( 10, 10 );
1797   Stage::GetCurrent().Add( rootActor );
1798
1799   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1800   NativeImageInterfacePtr testNativeImagePtr = TestNativeImage::New(10, 10);
1801   FrameBufferImage frameBufferImage = FrameBufferImage::New( *testNativeImagePtr.Get() );
1802
1803   RenderTask newTask = taskList.CreateTask();
1804   newTask.SetCameraActor( offscreenCameraActor );
1805   newTask.SetSourceActor( rootActor );
1806   newTask.SetInputEnabled( false );
1807   newTask.SetClearColor( Vector4( 0.f, 0.f, 0.f, 0.f ) );
1808   newTask.SetClearEnabled( true );
1809   newTask.SetExclusive( true );
1810   newTask.SetRefreshRate( RenderTask::REFRESH_ONCE );
1811   newTask.SetTargetFrameBuffer( frameBufferImage );
1812   newTask.SetProperty( RenderTask::Property::REQUIRES_SYNC, true );
1813
1814   bool finished = false;
1815   RenderTaskFinished renderTaskFinished( finished );
1816   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1817
1818   // Flush the queue and render.
1819   application.SendNotification();
1820
1821   // 1 render to process render task, then wait for sync before finished msg is sent
1822   // from update to the event thread.
1823
1824   application.Render();
1825   application.SendNotification();
1826   DALI_TEST_CHECK( !finished );
1827
1828   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
1829   DALI_TEST_CHECK( lastSyncObj != NULL );
1830
1831   application.Render();
1832   DALI_TEST_EQUALS( (Integration::KeepUpdating::Reasons)(application.GetUpdateStatus() & Integration::KeepUpdating::RENDER_TASK_SYNC), Integration::KeepUpdating::RENDER_TASK_SYNC, TEST_LOCATION );
1833   application.SendNotification();
1834   DALI_TEST_CHECK( !finished );
1835
1836   application.Render();
1837   DALI_TEST_EQUALS( (Integration::KeepUpdating::Reasons)(application.GetUpdateStatus() & Integration::KeepUpdating::RENDER_TASK_SYNC), Integration::KeepUpdating::RENDER_TASK_SYNC, TEST_LOCATION );
1838   application.SendNotification();
1839   DALI_TEST_CHECK( ! finished );
1840
1841   sync.SetObjectSynced( lastSyncObj, true );
1842
1843   application.Render();
1844   application.SendNotification();
1845   DALI_TEST_CHECK( !finished );
1846
1847   application.Render();
1848   application.SendNotification();
1849   DALI_TEST_CHECK( finished );
1850
1851   DALI_TEST_EQUALS( application.GetUpdateStatus(), 0, TEST_LOCATION );
1852   END_TEST;
1853 }
1854
1855
1856 int UtcDaliRenderTaskContinuous01(void)
1857 {
1858   TestApplication application;
1859
1860   tet_infoline("Testing RenderTask Render Continuous using loading image\nPRE: render task not ready (source actor not staged)\nPOST:continuous renders, no Finished signal");
1861
1862   // SETUP AN OFFSCREEN RENDER TASK
1863   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1864   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1865   drawTrace.Enable(true);
1866
1867   Actor rootActor = Actor::New();
1868   Stage::GetCurrent().Add( rootActor );
1869
1870   CameraActor offscreenCameraActor = CameraActor::New();
1871   Stage::GetCurrent().Add( offscreenCameraActor );
1872
1873   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
1874
1875   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1876   bool finished = false;
1877   RenderTaskFinished renderTaskFinished( finished );
1878   application.SendNotification();
1879
1880   // START PROCESS/RENDER                     Input,    Expected  Input, Expected, KeepUpdating
1881   DALI_TEST_CHECK( UpdateRender(application,  drawTrace, false,   finished, false, false, __LINE__ ) );
1882   application.GetPlatform().ClearReadyResources();
1883
1884   // ADD SOURCE ACTOR TO STAGE - expect continuous renders to start, no finished signal
1885   Stage::GetCurrent().Add(secondRootActor);
1886   application.SendNotification();
1887
1888   // CONTINUE PROCESS/RENDER                  Input,    Expected  Input,    Expected
1889   DALI_TEST_CHECK( UpdateRender(application,  drawTrace, true,    finished, false, false, __LINE__ ) );
1890   END_TEST;
1891 }
1892
1893
1894 int UtcDaliRenderTaskContinuous02(void)
1895 {
1896   TestApplication application;
1897
1898   tet_infoline("Testing RenderTask Render Continuous using loading image\nPRE: render task not ready (source actor not visible)\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   Stage::GetCurrent().Add( offscreenCameraActor );
1910
1911   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
1912   Stage::GetCurrent().Add(secondRootActor);
1913   secondRootActor.SetVisible(false);
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   application.SendNotification();
1920
1921   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected, KeepUpdating
1922   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, false, __LINE__ ) );
1923   application.GetPlatform().ClearReadyResources();
1924
1925   // MAKE SOURCE ACTOR VISIBLE - expect continuous renders to start, no finished signal
1926   secondRootActor.SetVisible(true);
1927   application.SendNotification();
1928
1929   // CONTINUE PROCESS/RENDER                 Input,    Expected  Input,    Expected
1930   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
1931   END_TEST;
1932 }
1933
1934 int UtcDaliRenderTaskContinuous03(void)
1935 {
1936   TestApplication application;
1937
1938   tet_infoline("Testing RenderTask Render Continuous using loading image\nPRE: render task not ready (camera actor not staged)\nPOST:continuous renders, no Finished signal");
1939
1940   // SETUP AN OFFSCREEN RENDER TASK
1941   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1942   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1943   drawTrace.Enable(true);
1944
1945   Actor rootActor = Actor::New();
1946   Stage::GetCurrent().Add( rootActor );
1947
1948   CameraActor offscreenCameraActor = CameraActor::New();
1949   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
1950   Stage::GetCurrent().Add(secondRootActor);
1951
1952   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1953   bool finished = false;
1954   RenderTaskFinished renderTaskFinished( finished );
1955   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1956   application.SendNotification();
1957
1958   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1959   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, false, __LINE__ ) );
1960   application.GetPlatform().ClearReadyResources();
1961
1962   // ADD CAMERA ACTOR TO STAGE - expect continuous renders to start, no finished signal
1963   Stage::GetCurrent().Add( offscreenCameraActor );
1964   application.SendNotification();
1965
1966   // CONTINUE PROCESS/RENDER                 Input,    Expected  Input,    Expected
1967   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
1968   END_TEST;
1969 }
1970
1971
1972 int UtcDaliRenderTaskContinuous04(void)
1973 {
1974   TestApplication application;
1975
1976   tet_infoline("Testing RenderTask Render Continuous using loaded image");
1977
1978   // SETUP AN OFFSCREEN RENDER TASK
1979   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1980   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1981   drawTrace.Enable(true);
1982
1983   Actor rootActor = Actor::New();
1984   Stage::GetCurrent().Add( rootActor );
1985
1986   CameraActor offscreenCameraActor = CameraActor::New();
1987   Stage::GetCurrent().Add( offscreenCameraActor );
1988   Actor secondRootActor = CreateRenderableActorFailed(application, "aFile.jpg");
1989   Stage::GetCurrent().Add(secondRootActor);
1990
1991   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1992   bool finished = false;
1993   RenderTaskFinished renderTaskFinished( finished );
1994   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1995   application.SendNotification();
1996
1997   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1998   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,   finished, false, false, __LINE__ ) );
1999   END_TEST;
2000 }
2001
2002 int UtcDaliRenderTaskOnce01(void)
2003 {
2004   TestApplication application;
2005
2006   tet_infoline("Testing RenderTask Render Once GlSync, using loaded image");
2007
2008   // SETUP AN OFFSCREEN RENDER TASK
2009   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2010   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2011   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2012   drawTrace.Enable(true);
2013
2014   Actor rootActor = Actor::New();
2015   Stage::GetCurrent().Add( rootActor );
2016
2017   CameraActor offscreenCameraActor = CameraActor::New();
2018   Stage::GetCurrent().Add( offscreenCameraActor );
2019   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2020
2021   Stage::GetCurrent().Add(secondRootActor);
2022
2023   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, true);
2024   bool finished = false;
2025   RenderTaskFinished renderTaskFinished( finished );
2026   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2027   application.SendNotification();
2028
2029   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,   finished, false, true, __LINE__  ) );
2030
2031   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2032   DALI_TEST_CHECK( lastSyncObj != NULL );
2033   sync.SetObjectSynced( lastSyncObj, true );
2034
2035   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__  ) );
2036   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__  ) );
2037   END_TEST;
2038 }
2039
2040 int UtcDaliRenderTaskOnce02(void)
2041 {
2042   TestApplication application;
2043
2044   tet_infoline("Testing RenderTask Render Once GlSync, using Mesh which accesses texture through sampler with loaded image.\n");
2045
2046   // SETUP AN OFFSCREEN RENDER TASK
2047   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2048   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2049   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2050   drawTrace.Enable(true);
2051
2052   Actor rootActor = Actor::New();
2053   Stage::GetCurrent().Add( rootActor );
2054
2055   CameraActor offscreenCameraActor = CameraActor::New();
2056   Stage::GetCurrent().Add( offscreenCameraActor );
2057
2058   Shader shader = CreateShader();
2059   Image image = CreateResourceImage(application, "aFile.jpg");
2060   TextureSet textureSet = CreateTextureSet( image );
2061
2062   Geometry geometry = CreateQuadGeometry();
2063   Renderer renderer = Renderer::New(geometry, shader);
2064   renderer.SetTextures( textureSet );
2065   Actor secondRootActor = Actor::New();
2066   secondRootActor.AddRenderer(renderer);
2067   secondRootActor.SetSize(100, 100);
2068   Stage::GetCurrent().Add(secondRootActor);
2069
2070   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, true);
2071   bool finished = false;
2072   RenderTaskFinished renderTaskFinished( finished );
2073   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2074   application.SendNotification();
2075
2076   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,   finished, false, true, __LINE__  ) );
2077
2078   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2079   DALI_TEST_CHECK( lastSyncObj != NULL );
2080   sync.SetObjectSynced( lastSyncObj, true );
2081
2082   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__  ) );
2083   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__  ) );
2084
2085    END_TEST;
2086 }
2087
2088 int UtcDaliRenderTaskOnce03(void)
2089 {
2090   TestApplication application;
2091
2092   tet_infoline("Testing RenderTask Render Once GlSync, using loaded image. Switch from render always after ready to render once\n");
2093
2094   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2095   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2096   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2097   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2098   drawTrace.Enable(true);
2099
2100   Actor rootActor = Actor::New();
2101   Stage::GetCurrent().Add( rootActor );
2102
2103   CameraActor offscreenCameraActor = CameraActor::New();
2104   Stage::GetCurrent().Add( offscreenCameraActor );
2105   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2106   Stage::GetCurrent().Add(secondRootActor);
2107
2108   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
2109   bool finished = false;
2110   RenderTaskFinished renderTaskFinished( finished );
2111   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2112   application.SendNotification();
2113
2114   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2115
2116   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2117   application.SendNotification();
2118
2119   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,   finished, false, true, __LINE__  ) );
2120
2121   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2122   DALI_TEST_CHECK( lastSyncObj != NULL );
2123   sync.SetObjectSynced( lastSyncObj, true );
2124
2125   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__  ) );
2126   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__  ) );
2127
2128   END_TEST;
2129 }
2130
2131
2132 int UtcDaliRenderTaskOnce04(void)
2133 {
2134   TestApplication application;
2135   tet_infoline("Testing RenderTask Render Once GlSync, using Mesh which accesses texture through sampler with loaded image.\n"
2136                "Switch from render always after ready to render once\n"
2137               );
2138
2139   // SETUP AN OFFSCREEN RENDER TASK
2140   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2141   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2142   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2143   drawTrace.Enable(true);
2144
2145   Actor rootActor = Actor::New();
2146   Stage::GetCurrent().Add( rootActor );
2147
2148   CameraActor offscreenCameraActor = CameraActor::New();
2149   Stage::GetCurrent().Add( offscreenCameraActor );
2150
2151   Shader shader = CreateShader();
2152   Image image = CreateResourceImage(application, "aFile.jpg");
2153   TextureSet textureSet = CreateTextureSet( image );
2154
2155   Geometry geometry = CreateQuadGeometry();
2156   Renderer renderer = Renderer::New(geometry, shader);
2157   renderer.SetTextures( textureSet );
2158   Actor secondRootActor = Actor::New();
2159   secondRootActor.AddRenderer(renderer);
2160   secondRootActor.SetSize(100, 100);
2161   Stage::GetCurrent().Add(secondRootActor);
2162
2163   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
2164   bool finished = false;
2165   RenderTaskFinished renderTaskFinished( finished );
2166   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2167   application.SendNotification();
2168
2169   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2170
2171   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2172   application.SendNotification();
2173
2174   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,   finished, false, true, __LINE__  ) );
2175
2176   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2177   DALI_TEST_CHECK( lastSyncObj != NULL );
2178   sync.SetObjectSynced( lastSyncObj, true );
2179
2180   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true, __LINE__  ) );
2181   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__  ) );
2182
2183   END_TEST;
2184 }
2185
2186 int UtcDaliRenderTaskOnceNoSync01(void)
2187 {
2188   TestApplication application;
2189
2190   tet_infoline("Testing RenderTask Render Once, \nPRE: Resources ready\nPOST: Finished signal sent once only");
2191
2192   // SETUP AN OFFSCREEN RENDER TASK
2193   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2194   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2195   drawTrace.Enable(true);
2196
2197   Actor rootActor = Actor::New();
2198   Stage::GetCurrent().Add( rootActor );
2199
2200   CameraActor offscreenCameraActor = CameraActor::New();
2201   Stage::GetCurrent().Add( offscreenCameraActor );
2202   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2203   Stage::GetCurrent().Add(secondRootActor);
2204
2205   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, false);
2206   bool finished = false;
2207   RenderTaskFinished renderTaskFinished( finished );
2208   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2209   application.SendNotification();
2210
2211   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2212   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__ ) );
2213   END_TEST;
2214 }
2215
2216 int UtcDaliRenderTaskOnceNoSync02(void)
2217 {
2218   TestApplication application;
2219
2220   tet_infoline("Testing RenderTask Render Once, using Mesh which accesses texture through sampler with loaded image.\n"
2221                "PRE: Resources ready\nPOST: Finished signal sent once only");
2222   // SETUP AN OFFSCREEN RENDER TASK
2223   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2224   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2225   drawTrace.Enable(true);
2226
2227   Actor rootActor = Actor::New();
2228   Stage::GetCurrent().Add( rootActor );
2229
2230   CameraActor offscreenCameraActor = CameraActor::New();
2231   Stage::GetCurrent().Add( offscreenCameraActor );
2232
2233   Shader shader = CreateShader();
2234   Image image = CreateResourceImage(application, "aFile.jpg");
2235   TextureSet textureSet = CreateTextureSet( image );
2236
2237   Geometry geometry = CreateQuadGeometry();
2238   Renderer renderer = Renderer::New(geometry, shader);
2239   renderer.SetTextures( textureSet );
2240   Actor secondRootActor = Actor::New();
2241   secondRootActor.AddRenderer(renderer);
2242   secondRootActor.SetSize(100, 100);
2243   Stage::GetCurrent().Add(secondRootActor);
2244
2245   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, false);
2246   bool finished = false;
2247   RenderTaskFinished renderTaskFinished( finished );
2248   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2249   application.SendNotification();
2250
2251   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2252   application.GetPlatform().ClearReadyResources();
2253   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__ ) );
2254
2255   END_TEST;
2256 }
2257
2258 int UtcDaliRenderTaskOnceNoSync03(void)
2259 {
2260   TestApplication application;
2261
2262   tet_infoline("Testing RenderTask Render Once, using loaded image. Switch from render always after ready to render once\n"
2263                "PRE: Render task ready, Image loaded\n"
2264                "POST: Finished signal sent only once");
2265
2266   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2267   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2268   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2269   drawTrace.Enable(true);
2270
2271   Actor rootActor = Actor::New();
2272   Stage::GetCurrent().Add( rootActor );
2273
2274   CameraActor offscreenCameraActor = CameraActor::New();
2275   Stage::GetCurrent().Add( offscreenCameraActor );
2276   Actor secondRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2277   Stage::GetCurrent().Add(secondRootActor);
2278
2279   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2280   bool finished = false;
2281   RenderTaskFinished renderTaskFinished( finished );
2282   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2283   application.SendNotification();
2284
2285   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2286
2287   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2288   application.SendNotification(); //         Input,    Expected  Input,    Expected
2289   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2290   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__ ) );
2291   END_TEST;
2292 }
2293
2294 int UtcDaliRenderTaskOnceNoSync04(void)
2295 {
2296   TestApplication application;
2297
2298   tet_infoline("Testing RenderTask Render Once, using Mesh which accesses texture through sampler with loading image.\n"
2299                "Switch from render always after ready to render once\n"
2300                "PRE: Render task ready, Image not loaded\n"
2301                "POST: Finished signal sent only once");
2302
2303   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2304   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2305   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2306   drawTrace.Enable(true);
2307
2308   Actor rootActor = Actor::New();
2309   Stage::GetCurrent().Add( rootActor );
2310
2311   CameraActor offscreenCameraActor = CameraActor::New();
2312   Stage::GetCurrent().Add( offscreenCameraActor );
2313
2314   Shader shader = CreateShader();
2315   Image image = CreateResourceImage(application, "aFile.jpg");
2316   TextureSet textureSet = CreateTextureSet( image );
2317
2318   Geometry geometry = CreateQuadGeometry();
2319   Renderer renderer = Renderer::New(geometry, shader);
2320   renderer.SetTextures( textureSet );
2321   Actor secondRootActor = Actor::New();
2322   secondRootActor.AddRenderer(renderer);
2323   secondRootActor.SetSize(100, 100);
2324   Stage::GetCurrent().Add(secondRootActor);
2325
2326
2327   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2328   bool finished = false;
2329   RenderTaskFinished renderTaskFinished( finished );
2330   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2331   application.SendNotification();
2332
2333   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2334   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2335   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2336   DALI_TEST_CHECK( lastSyncObj == NULL );
2337
2338   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2339   application.SendNotification(); //         Input,    Expected  Input,    Expected
2340   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true, __LINE__ ) );
2341   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false, __LINE__ ) );
2342
2343   lastSyncObj = sync.GetLastSyncObject();
2344   DALI_TEST_CHECK( lastSyncObj == NULL );
2345
2346   END_TEST;
2347 }
2348
2349 int UtcDaliRenderTaskOnceNoSync05(void)
2350 {
2351   TestApplication application;
2352
2353   tet_infoline("Testing RenderTask Render Once\n"
2354                "SetRefreshRate(ONCE), resource load failed, completes render task.\n"
2355                "PRE: resources failed to load\n"
2356                "POST: No finished signal sent.");
2357
2358   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2359   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2360   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2361   drawTrace.Enable(true);
2362
2363   Actor rootActor = Actor::New();
2364   Stage::GetCurrent().Add( rootActor );
2365
2366   CameraActor offscreenCameraActor = CameraActor::New();
2367   Stage::GetCurrent().Add( offscreenCameraActor );
2368   Actor secondRootActor = CreateRenderableActorFailed(application, "aFile.jpg");
2369   Stage::GetCurrent().Add(secondRootActor);
2370
2371   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2372   bool finished = false;
2373   RenderTaskFinished renderTaskFinished( finished );
2374   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2375   application.SendNotification();
2376
2377   // START PROCESS/RENDER                    Input,     Expected  Input,    Expected
2378   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2379
2380   // CHANGE TO RENDER ONCE,
2381   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2382   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false, __LINE__ ) );
2383
2384   END_TEST;
2385 }
2386
2387
2388
2389 int UtcDaliRenderTaskOnceChain01(void)
2390 {
2391   TestApplication application;
2392
2393   tet_infoline("Testing RenderTask Render Once Chained render tasks\n"
2394                "SetRefreshRate(ONCE), resource load completes, both render tasks render.\n"
2395                "PRE: resources ready\n"
2396                "POST: 2 finished signals sent.");
2397
2398   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2399   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2400   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2401   drawTrace.Enable(true);
2402
2403   Actor defaultRootActor = Actor::New(); // Root for default RT
2404   Stage::GetCurrent().Add( defaultRootActor );
2405
2406   CameraActor offscreenCameraActor = CameraActor::New();
2407   Stage::GetCurrent().Add( offscreenCameraActor );
2408   Actor firstRootActor = CreateRenderableActorSuccess(application, "aFile.jpg");
2409   Stage::GetCurrent().Add(firstRootActor);
2410
2411   // first render task
2412   RenderTask firstTask = CreateRenderTask(application, offscreenCameraActor, defaultRootActor, firstRootActor, RenderTask::REFRESH_ONCE, false);
2413   bool firstFinished = false;
2414   RenderTaskFinished renderTask1Finished( firstFinished );
2415   firstTask.FinishedSignal().Connect( &application, renderTask1Finished );
2416
2417   // Second render task
2418   FrameBufferImage fbo = firstTask.GetTargetFrameBuffer();
2419   Actor secondRootActor = CreateRenderableActor( fbo );
2420   Stage::GetCurrent().Add(secondRootActor);
2421   RenderTask secondTask = CreateRenderTask(application, offscreenCameraActor, defaultRootActor, secondRootActor, RenderTask::REFRESH_ONCE, false);
2422   bool secondFinished = false;
2423   RenderTaskFinished renderTask2Finished( secondFinished );
2424   secondTask.FinishedSignal().Connect( &application, renderTask2Finished );
2425
2426   application.SendNotification();
2427
2428   //Both render tasks are executed.
2429   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,  firstFinished, false, true, __LINE__ ) );
2430   DALI_TEST_CHECK( firstFinished == false );
2431   DALI_TEST_CHECK( secondFinished == false );
2432
2433   //Nothing else to render and both render task should have finished now
2434   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,  firstFinished, true, false, __LINE__ ) );
2435   DALI_TEST_CHECK( firstFinished == true );
2436   DALI_TEST_CHECK( secondFinished == true );
2437
2438   END_TEST;
2439 }
2440
2441 int UtcDaliRenderTaskProperties(void)
2442 {
2443   TestApplication application;
2444
2445   RenderTask task = Stage::GetCurrent().GetRenderTaskList().CreateTask();
2446
2447   Property::IndexContainer indices;
2448   task.GetPropertyIndices( indices );
2449   DALI_TEST_CHECK( indices.Size() );
2450   DALI_TEST_EQUALS( indices.Size(), task.GetPropertyCount(), TEST_LOCATION );
2451   END_TEST;
2452 }
2453
2454 int UtcDaliRenderTaskSetScreenToFrameBufferMappingActor(void)
2455 {
2456   TestApplication application;
2457   tet_infoline("Testing RenderTask::SetScreenToFrameBufferMappingActor ");
2458
2459   Stage stage = Stage::GetCurrent();
2460   Size stageSize = stage.GetSize();
2461   Actor mappingActor = Actor::New();
2462   Vector2 scale( 0.6f, 0.75f);
2463   Vector2 offset( stageSize.x*0.1f, stageSize.y*0.15f);
2464   mappingActor.SetSize( stageSize * scale );
2465   mappingActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2466   mappingActor.SetPosition( offset.x, offset.y );
2467   stage.Add( mappingActor );
2468
2469   Actor offscreenActor = Actor::New();
2470   offscreenActor.SetSize( stageSize );
2471   offscreenActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2472   stage.Add( offscreenActor );
2473
2474   RenderTaskList taskList = stage.GetRenderTaskList();
2475   RenderTask renderTask = taskList.CreateTask();
2476   FrameBufferImage frameBufferImage =  FrameBufferImage::New(stageSize.width*scale.x, stageSize.height*scale.y, Pixel::A8);
2477   renderTask.SetSourceActor( offscreenActor );
2478   renderTask.SetExclusive( true );
2479   renderTask.SetInputEnabled( true );
2480   renderTask.SetTargetFrameBuffer( frameBufferImage );
2481   renderTask.SetRefreshRate( RenderTask::REFRESH_ONCE );
2482   renderTask.SetScreenToFrameBufferMappingActor( mappingActor );
2483   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2484
2485   // Render and notify
2486   application.SendNotification();
2487   application.Render();
2488   application.Render();
2489   application.SendNotification();
2490
2491   Vector2 screenCoordinates( stageSize.x * 0.05f, stageSize.y * 0.05f );
2492   Dali::HitTestAlgorithm::Results results;
2493   DALI_TEST_CHECK( !results.actor );
2494   DALI_TEST_EQUALS( Vector2::ZERO, results.actorCoordinates, 0.1f, TEST_LOCATION );
2495   // miss expected, results not changed
2496   DALI_TEST_CHECK( false == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
2497   DALI_TEST_CHECK( !results.actor );
2498   DALI_TEST_EQUALS( Vector2::ZERO, results.actorCoordinates, 0.1f, TEST_LOCATION );
2499
2500   screenCoordinates.x = stageSize.x * 0.265f;
2501   screenCoordinates.y = stageSize.y * 0.33f;
2502   results.actor = Actor();
2503   results.actorCoordinates = Vector2::ZERO;
2504   // hit expected, results changed
2505   DALI_TEST_CHECK( true == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
2506   DALI_TEST_CHECK( results.actor  == offscreenActor );
2507   DALI_TEST_EQUALS( (screenCoordinates-offset)/scale , results.actorCoordinates, 0.1f, TEST_LOCATION );
2508
2509   screenCoordinates.x = stageSize.x * 0.435f;
2510   screenCoordinates.y = stageSize.y * 0.52f;
2511   // hit expected, results changed
2512   DALI_TEST_CHECK( true == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
2513   DALI_TEST_CHECK( results.actor  == offscreenActor );
2514   const Vector2 expectedCoordinates = (screenCoordinates-offset)/scale;
2515   DALI_TEST_EQUALS( expectedCoordinates , results.actorCoordinates, 0.1f, TEST_LOCATION );
2516
2517   screenCoordinates.x = stageSize.x * 0.65f;
2518   screenCoordinates.y = stageSize.y * 0.95f;
2519   // miss expected, results not changed
2520   DALI_TEST_CHECK( false == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
2521   DALI_TEST_CHECK( results.actor  == offscreenActor );
2522   DALI_TEST_EQUALS( expectedCoordinates , results.actorCoordinates, 0.1f, TEST_LOCATION );
2523   END_TEST;
2524 }
2525
2526 int UtcDaliRenderTaskFinishInvisibleSourceActor(void)
2527 {
2528   TestApplication application;
2529
2530   tet_infoline("Testing RenderTask::FinishInvisibleSourceActor()");
2531
2532   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2533   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
2534
2535   CameraActor offscreenCameraActor = CameraActor::New();
2536
2537   Stage::GetCurrent().Add( offscreenCameraActor );
2538
2539   BufferImage image = BufferImage::New( 10, 10 );
2540   Actor rootActor = CreateRenderableActor( image );
2541   rootActor.SetSize( 10, 10 );
2542   rootActor.SetVisible(false);
2543   Stage::GetCurrent().Add( rootActor );
2544
2545   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
2546   NativeImageInterfacePtr testNativeImagePtr = TestNativeImage::New(10, 10);
2547   FrameBufferImage frameBufferImage = FrameBufferImage::New( *testNativeImagePtr.Get() );
2548
2549   // Flush all outstanding messages
2550   application.SendNotification();
2551   application.Render();
2552
2553   RenderTask newTask = taskList.CreateTask();
2554   newTask.SetCameraActor( offscreenCameraActor );
2555   newTask.SetSourceActor( rootActor );
2556   newTask.SetInputEnabled( false );
2557   newTask.SetClearColor( Vector4( 0.f, 0.f, 0.f, 0.f ) );
2558   newTask.SetClearEnabled( true );
2559   newTask.SetExclusive( true );
2560   newTask.SetRefreshRate( RenderTask::REFRESH_ONCE );
2561   newTask.SetTargetFrameBuffer( frameBufferImage );
2562   newTask.SetProperty( RenderTask::Property::REQUIRES_SYNC, true );
2563
2564   // Framebuffer doesn't actually get created until Connected, i.e. by previous line
2565
2566   bool finished = false;
2567   RenderTaskFinished renderTaskFinished( finished );
2568   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2569
2570   // Flush the queue and render.
2571   application.SendNotification();
2572
2573   // 1 render to process render task, then wait for sync before finished msg is sent
2574   // from update to the event thread.
2575
2576   application.Render();
2577   application.SendNotification();
2578   DALI_TEST_CHECK( !finished );
2579
2580   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
2581   DALI_TEST_CHECK( lastSyncObj != NULL );
2582
2583   application.Render();
2584   DALI_TEST_EQUALS( (Integration::KeepUpdating::Reasons)(application.GetUpdateStatus() & Integration::KeepUpdating::RENDER_TASK_SYNC), Integration::KeepUpdating::RENDER_TASK_SYNC, TEST_LOCATION );
2585   application.SendNotification();
2586   DALI_TEST_CHECK( !finished );
2587
2588   application.Render();
2589   DALI_TEST_EQUALS( (Integration::KeepUpdating::Reasons)(application.GetUpdateStatus() & Integration::KeepUpdating::RENDER_TASK_SYNC), Integration::KeepUpdating::RENDER_TASK_SYNC, TEST_LOCATION );
2590   application.SendNotification();
2591   DALI_TEST_CHECK( ! finished );
2592
2593   sync.SetObjectSynced( lastSyncObj, true );
2594
2595   application.Render();
2596   application.SendNotification();
2597   DALI_TEST_CHECK( !finished );
2598
2599   application.Render();
2600   application.SendNotification();
2601   DALI_TEST_CHECK( finished );
2602   finished = false;
2603
2604   application.Render(); // Double check no more finished signal
2605   application.SendNotification();
2606   DALI_TEST_CHECK( ! finished );
2607
2608   END_TEST;
2609 }
2610
2611 int UtcDaliRenderTaskFinishMissingImage(void)
2612 {
2613   TestApplication application;
2614
2615   // Previously we had bugs where not having a resource ID would cause render-tasks to wait forever
2616   tet_infoline("Testing RenderTask::SignalFinished() when an Actor has no Image set");
2617
2618   Stage stage = Stage::GetCurrent();
2619
2620   BufferImage image = BufferImage::New( 10, 10 );
2621   Actor rootActor = CreateRenderableActor( image );
2622   rootActor.SetSize( 10, 10 );
2623   stage.Add( rootActor );
2624
2625   Actor actorWithMissingImage = CreateRenderableActor( Image() );
2626   actorWithMissingImage.SetSize( 10, 10 );
2627   stage.Add( actorWithMissingImage );
2628
2629   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
2630   RenderTask newTask = taskList.CreateTask();
2631   newTask.SetInputEnabled( false );
2632   newTask.SetClearColor( Vector4( 0.f, 0.f, 0.f, 0.f ) );
2633   newTask.SetClearEnabled( true );
2634   newTask.SetExclusive( true );
2635   newTask.SetRefreshRate( RenderTask::REFRESH_ONCE );
2636
2637   bool finished = false;
2638   RenderTaskFinished renderTaskFinished( finished );
2639   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2640
2641   // 1 render to process render task, then 1 before finished msg is sent from update to the event thread.
2642   application.SendNotification();
2643   application.Render();
2644   application.Render();
2645
2646   application.SendNotification();
2647   DALI_TEST_CHECK( finished );
2648
2649   END_TEST;
2650 }
2651
2652 int UtcDaliRenderTaskWorldToViewport(void)
2653 {
2654   TestApplication application( static_cast<size_t>(400), static_cast<size_t>(400) ); // square surface
2655
2656   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
2657
2658   Actor actor = Actor::New();
2659   actor.SetSize(100.0f, 100.0f);
2660   actor.SetPosition( Vector3(0.0, 0.0, 0.0) );
2661
2662   actor.SetParentOrigin( Vector3(0.5, 0.5, 0.5) );
2663   actor.SetAnchorPoint( Vector3(0.5, 0.5, 0.5) );
2664
2665   Stage::GetCurrent().Add(actor);
2666
2667   application.SendNotification();
2668   application.Render();
2669   application.SendNotification();
2670
2671   RenderTask task = taskList.GetTask( 0u );
2672
2673   CameraActor camera = task.GetCameraActor();
2674
2675   Vector2 screenSize = task.GetCurrentViewportSize();
2676
2677   float screenX = 0.0;
2678   float screenY = 0.0;
2679
2680   bool ok = task.WorldToViewport(actor.GetCurrentWorldPosition(), screenX, screenY);
2681   DALI_TEST_CHECK(ok == true);
2682
2683   DALI_TEST_EQUALS(screenX, screenSize.x/2, Math::MACHINE_EPSILON_10000, TEST_LOCATION);
2684   DALI_TEST_EQUALS(screenY, screenSize.y/2, Math::MACHINE_EPSILON_10000, TEST_LOCATION);
2685
2686   Actor actor2 = Actor::New();
2687   float actor2Size = 100.f;
2688   actor2.SetSize( actor2Size, actor2Size );
2689   actor2.SetPosition( Vector3(0.0, 0.0, 0.0) );
2690   actor2.SetParentOrigin( Vector3(0.5, 0.5, 0.0) );
2691   actor2.SetAnchorPoint( Vector3(0.5, 0.5, 0.0) );
2692   Stage::GetCurrent().Add( actor2 );
2693   actor2.Add(actor);
2694   actor.SetParentOrigin( Vector3(0,0,0) );
2695
2696   application.SendNotification();
2697   application.Render();
2698   application.SendNotification();
2699
2700   ok = task.WorldToViewport(actor.GetCurrentWorldPosition(), screenX, screenY);
2701   DALI_TEST_CHECK(ok == true);
2702
2703   DALI_TEST_EQUALS(screenX, screenSize.x/2 - actor2Size/2, Math::MACHINE_EPSILON_10000, TEST_LOCATION);
2704   DALI_TEST_EQUALS(screenY, screenSize.y/2 - actor2Size/2, Math::MACHINE_EPSILON_10000, TEST_LOCATION);
2705
2706   END_TEST;
2707 }
2708
2709
2710 int UtcDaliRenderTaskViewportToLocal(void)
2711 {
2712   TestApplication application;
2713   Actor actor = Actor::New();
2714   actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
2715   actor.SetSize(100.0f, 100.0f);
2716   actor.SetPosition(10.0f, 10.0f);
2717   Stage::GetCurrent().Add(actor);
2718
2719   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
2720   RenderTask task = taskList.GetTask( 0u );
2721
2722   // flush the queue and render once
2723   application.SendNotification();
2724   application.Render();
2725   application.SendNotification();
2726   application.Render();
2727
2728   float localX;
2729   float localY;
2730
2731   float rtLocalX;
2732   float rtLocalY;
2733
2734   float screenX = 50.0f;
2735   float screenY = 50.0f;
2736
2737   DALI_TEST_CHECK( actor.ScreenToLocal(localX, localY, screenX, screenY) );
2738
2739   DALI_TEST_CHECK( task.ViewportToLocal(actor, screenX, screenY, rtLocalX, rtLocalY ) );
2740
2741   DALI_TEST_EQUALS(localX, rtLocalX, 0.01f, TEST_LOCATION);
2742   DALI_TEST_EQUALS(localY, rtLocalY, 0.01f, TEST_LOCATION);
2743
2744   END_TEST;
2745
2746 }
2747
2748 int UtcDaliRenderTaskRequiresSync(void)
2749 {
2750   TestApplication application;
2751   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
2752
2753   RenderTask newTask = taskList.CreateTask();
2754   newTask.SetProperty( RenderTask::Property::REQUIRES_SYNC, false );
2755
2756   DALI_TEST_EQUALS( newTask.GetProperty< bool >( RenderTask::Property::REQUIRES_SYNC ), false, TEST_LOCATION );
2757   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< bool >( newTask, RenderTask::Property::REQUIRES_SYNC ), false, TEST_LOCATION );
2758
2759   newTask.SetProperty( RenderTask::Property::REQUIRES_SYNC, true );
2760
2761   DALI_TEST_EQUALS( newTask.GetProperty< bool >( RenderTask::Property::REQUIRES_SYNC ), true, TEST_LOCATION );
2762   DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< bool >( newTask, RenderTask::Property::REQUIRES_SYNC ), true, TEST_LOCATION );
2763
2764   END_TEST;
2765 }