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