Merge remote-tracking branch 'origin/tizen' into new_text
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-RenderTask.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <iostream>
19
20 #include <stdlib.h>
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
23 #include <dali/integration-api/debug.h>
24
25 #define BOOLSTR(x) ((x)?"T":"F")
26
27
28 using namespace Dali;
29
30 void utc_dali_render_task_startup(void)
31 {
32   test_return_value = TET_UNDEF;
33 }
34
35 void utc_dali_render_task_cleanup(void)
36 {
37   test_return_value = TET_PASS;
38 }
39
40 namespace // unnamed namespace
41 {
42
43 class TestNativeImage : public NativeImage
44 {
45 public:
46   int mWidth;
47   int mHeight;
48   TestNativeImage(int width, int height)
49   : mWidth(width),
50     mHeight(height)
51   {}
52
53   virtual bool GlExtensionCreate() {return true;};
54
55   /**
56    * Destroy the GL resource for the NativeImage.
57    * e.g. For the EglImageKHR extension, this corresponds to calling eglDestroyImageKHR()
58    * @pre There is a GL context for the current thread.
59    */
60   virtual void GlExtensionDestroy() {};
61
62   /**
63    * Use the NativeImage as a texture for rendering
64    * @pre There is a GL context for the current thread.
65    * @return A GL error code
66    */
67   virtual unsigned int TargetTexture() {return 0;};
68
69   /**
70    * Called in each NativeTexture::Bind() call to allow implementation specific operations.
71    * The correct texture sampler has already been bound before the function gets called.
72    * @pre glAbstraction is being used by context in current thread
73    */
74   virtual void PrepareTexture() {}
75
76   /**
77    * Returns the width of the NativeImage
78    * @return width
79    */
80   virtual unsigned int GetWidth() const {return mWidth;}
81
82   /**
83    * Returns the height of the NativeImage
84    * @return height
85    */
86   virtual unsigned int GetHeight() const {return mHeight;}
87
88   /**
89    * Returns the internal pixel NativeImage::PixelFormat of the NativeImage
90    * @return pixel format
91    */
92   virtual Pixel::Format GetPixelFormat() const { return Pixel::RGBA8888; }
93 protected:
94   ~TestNativeImage(){}
95 };
96
97
98 const int RENDER_FRAME_INTERVAL = 16;                           ///< Duration of each frame in ms. (at approx 60FPS)
99
100 /*
101  * Simulate time passed by.
102  *
103  * @note this will always process at least 1 frame (1/60 sec)
104  *
105  * @param application Test application instance
106  * @param duration Time to pass in milliseconds.
107  * @return The actual time passed in milliseconds
108  */
109 int Wait(TestApplication& application, int duration = 0)
110 {
111   int time = 0;
112
113   for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
114   {
115     application.SendNotification();
116     application.Render(RENDER_FRAME_INTERVAL);
117     time += RENDER_FRAME_INTERVAL;
118   }
119
120   return time;
121 }
122
123 struct RenderTaskFinished
124 {
125   RenderTaskFinished( bool& finished )
126   : finished( finished )
127   {
128   }
129
130   void operator()( RenderTask& renderTask )
131   {
132     finished = true;
133   }
134
135   bool& finished;
136 };
137
138 struct RenderTaskFinishedRemoveSource
139 {
140   RenderTaskFinishedRemoveSource( bool& finished )
141   : finished( finished ),
142     finishedOnce(false)
143   {
144   }
145
146   void operator()( RenderTask& renderTask )
147   {
148     DALI_TEST_CHECK(finishedOnce == false);
149     finished = true;
150     finishedOnce = true;
151     Actor srcActor = renderTask.GetSourceActor();
152     UnparentAndReset(srcActor);
153   }
154
155   bool& finished;
156   bool finishedOnce;
157 };
158
159 struct RenderTaskFinishedRenderAgain
160 {
161   RenderTaskFinishedRenderAgain( bool& finished )
162   : finished( finished ),
163     finishedOnce(false)
164   {
165   }
166
167   void operator()( RenderTask& renderTask )
168   {
169     DALI_TEST_CHECK(finishedOnce == false);
170     finished = true;
171     finishedOnce = true;
172     renderTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
173   }
174
175   bool& finished;
176   bool finishedOnce;
177 };
178
179
180 bool TestScreenToFrameBufferFunction( Vector2& coordinates )
181 {
182   coordinates = coordinates + Vector2( 1, 2 );
183
184   return true;
185 }
186
187 ImageActor CreateLoadingImage(TestApplication& application, std::string filename, Image::LoadPolicy loadPolicy, Image::ReleasePolicy releasePolicy)
188 {
189   Image image = Image::New(filename, loadPolicy, releasePolicy);
190   DALI_TEST_CHECK( image );
191   application.SendNotification();
192   application.Render(16);
193   DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) );
194   ImageActor actor = ImageActor::New(image);
195   actor.SetSize( 80, 80 );
196   application.SendNotification();
197   application.Render(16);
198   return actor;
199 }
200
201 void CompleteImageLoad(TestApplication& application, Integration::ResourceId resourceId, Integration::ResourceTypeId requestType)
202 {
203   std::vector<GLuint> ids;
204   ids.push_back( 23 );
205   application.GetGlAbstraction().SetNextTextureIds( ids );
206
207   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::DISCARD );
208   Integration::ResourcePointer resource(bitmap);
209   bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
210
211   application.GetPlatform().SetResourceLoaded(resourceId, requestType, resource);
212 }
213
214 void FailImageLoad(TestApplication& application, Integration::ResourceId resourceId )
215 {
216   application.GetPlatform().SetResourceLoadFailed(resourceId, Integration::FailureUnknown);
217 }
218
219 void ReloadImage(TestApplication& application, Image image)
220 {
221   application.GetPlatform().ClearReadyResources();
222   application.GetPlatform().DiscardRequest();
223   application.GetPlatform().ResetTrace();
224   application.GetPlatform().SetClosestImageSize(Vector2(80.0f, 80.0f)); // Ensure reload is called.
225   image.Reload();
226 }
227
228 RenderTask CreateRenderTask(TestApplication& application,
229                             CameraActor offscreenCamera,
230                             Actor rootActor,       // Reset default render task to point at this actor
231                             Actor secondRootActor, // Source actor
232                             unsigned int refreshRate,
233                             bool glSync)
234 {
235   // Change main render task to use a different root
236   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
237   taskList.GetTask(0u).SetSourceActor( rootActor );
238
239   FrameBufferImage frameBufferImage;
240   if( glSync )
241   {
242     NativeImagePtr testNativeImagePtr = new TestNativeImage(10, 10);
243     frameBufferImage= FrameBufferImage::New( *testNativeImagePtr.Get() );
244   }
245   else
246   {
247     frameBufferImage = FrameBufferImage::New( 10, 10 );
248   }
249
250   // Don't draw output framebuffer
251
252   RenderTask newTask = taskList.CreateTask();
253   newTask.SetCameraActor( offscreenCamera );
254   newTask.SetSourceActor( secondRootActor );
255   newTask.SetInputEnabled( false );
256   newTask.SetClearColor( Vector4( 0.f, 0.f, 0.f, 0.f ) );
257   newTask.SetClearEnabled( true );
258   newTask.SetExclusive( true );
259   newTask.SetRefreshRate( refreshRate );
260   newTask.SetTargetFrameBuffer( frameBufferImage );
261   return newTask;
262 }
263
264 bool UpdateRender(TestApplication& application, TraceCallStack& callStack, bool testDrawn, bool& finishedSig, bool testFinished, bool testKeepUpdating )
265 {
266   finishedSig = false;
267   callStack.Reset();
268   application.Render(16);
269   application.SendNotification();
270
271   bool sigPassed = false;
272   if( testFinished )
273   {
274     sigPassed = finishedSig;
275   }
276   else
277   {
278     sigPassed = ! finishedSig;
279   }
280
281   bool drawResult = callStack.FindMethod("DrawElements") || callStack.FindMethod("DrawArrays");
282
283   bool drawPassed = false;
284   if( testDrawn )
285   {
286     drawPassed = drawResult;
287   }
288   else
289   {
290     drawPassed = !drawResult;
291   }
292
293   bool keepUpdating = (application.GetUpdateStatus() != 0);
294   bool keepUpdatingPassed = false;
295   if( testKeepUpdating )
296   {
297     keepUpdatingPassed = keepUpdating;
298   }
299   else
300   {
301     keepUpdatingPassed = !keepUpdating;
302   }
303
304   bool result = (sigPassed && drawPassed && keepUpdatingPassed);
305
306   tet_printf("UpdateRender: Expected: Draw:%s Signal:%s Keep Updating: %s  Actual: Draw:%s  Signal:%s KeepUpdating: %s  %s\n",
307              BOOLSTR(testDrawn), BOOLSTR(testFinished), BOOLSTR(testKeepUpdating),
308              BOOLSTR(drawResult), BOOLSTR(finishedSig), BOOLSTR(keepUpdating),
309              result ? "Passed":"Failed");
310
311   return result;
312 }
313
314 } // unnamed namespace
315
316
317 /****************************************************************************************************/
318 /****************************************************************************************************/
319 /********************************   TEST CASES BELOW   **********************************************/
320 /****************************************************************************************************/
321 /****************************************************************************************************/
322
323 int UtcDaliRenderTaskDownCast(void)
324 {
325   TestApplication application;
326
327   tet_infoline("Testing RenderTask::DownCast()");
328
329   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
330
331   BaseHandle base = taskList.GetTask( 0u );
332   DALI_TEST_CHECK( base );
333
334   RenderTask task = RenderTask::DownCast( base );
335   DALI_TEST_CHECK( task );
336
337   // Try calling a method
338   DALI_TEST_CHECK( task.GetSourceActor() );
339   END_TEST;
340 }
341
342 int UtcDaliRenderTaskSetSourceActor(void)
343 {
344   TestApplication application;
345
346   tet_infoline("Testing RenderTask::SetSourceActor()");
347
348   Stage stage = Stage::GetCurrent();
349
350   const std::vector<GLuint>& boundTextures = application.GetGlAbstraction().GetBoundTextures( GL_TEXTURE0 );
351
352   RenderTaskList taskList = stage.GetRenderTaskList();
353
354   RenderTask task = taskList.GetTask( 0u );
355
356   Actor actor = task.GetSourceActor();
357   DALI_TEST_CHECK( actor );
358
359   std::vector<GLuint> ids;
360   ids.push_back( 7 );
361   application.GetGlAbstraction().SetNextTextureIds( ids );
362
363   BitmapImage img = BitmapImage::New( 1,1 );
364   ImageActor newActor = ImageActor::New( img );
365   newActor.SetSize(1,1);
366   stage.Add( newActor );
367
368   Actor nonRenderableActor = Actor::New();
369   stage.Add( nonRenderableActor );
370
371   // Stop the newActor from being rendered by changing the source actor
372   DALI_TEST_CHECK( nonRenderableActor );
373   task.SetSourceActor( nonRenderableActor );
374   DALI_TEST_CHECK( task.GetSourceActor() != actor );
375   DALI_TEST_CHECK( task.GetSourceActor() == nonRenderableActor );
376
377   // Update & Render nothing!
378   application.GetGlAbstraction().ClearBoundTextures();
379   application.SendNotification();
380   application.Render();
381
382   // Check that nothing was rendered
383   DALI_TEST_EQUALS( boundTextures.size(), 0u, TEST_LOCATION );
384
385   // Set newActor as the new source Actor
386   task.SetSourceActor( newActor );
387   DALI_TEST_CHECK( task.GetSourceActor() != actor );
388   DALI_TEST_CHECK( task.GetSourceActor() == newActor );
389
390   // Update & Render the newActor
391   application.GetGlAbstraction().ClearBoundTextures();
392   application.SendNotification();
393   application.Render();
394
395   // Check that the newActor was rendered
396   DALI_TEST_EQUALS( boundTextures.size(), 1u, TEST_LOCATION );
397   if ( boundTextures.size() )
398   {
399     DALI_TEST_EQUALS( boundTextures[0], 7u, TEST_LOCATION );
400   }
401   END_TEST;
402 }
403
404 int UtcDaliRenderTaskSetSourceActorOffStage(void)
405 {
406   TestApplication application;
407
408   tet_infoline("Testing RenderTask::SetSourceActor (on/off stage testing)");
409
410   Stage stage = Stage::GetCurrent();
411
412   const std::vector<GLuint>& boundTextures = application.GetGlAbstraction().GetBoundTextures( GL_TEXTURE0 );
413
414   RenderTaskList taskList = stage.GetRenderTaskList();
415
416   RenderTask task = taskList.GetTask( 0u );
417
418   Actor actor = task.GetSourceActor();
419   DALI_TEST_CHECK( actor );
420
421   std::vector<GLuint> ids;
422   GLuint expectedTextureId( 3 );
423   ids.push_back( expectedTextureId );
424   application.GetGlAbstraction().SetNextTextureIds( ids );
425
426   BitmapImage img = BitmapImage::New( 1,1 );
427   ImageActor newActor = ImageActor::New( img );
428   newActor.SetSize(1,1);
429   task.SetSourceActor( newActor );
430   // Don't add newActor to stage yet
431
432   // Update & Render with the actor initially off-stage
433   application.GetGlAbstraction().ClearBoundTextures();
434   application.SendNotification();
435   application.Render();
436
437   // Check that nothing was rendered
438   DALI_TEST_EQUALS( boundTextures.size(), 0u, TEST_LOCATION );
439
440   // Now add to stage
441   stage.Add( newActor );
442
443   // Update & Render with the actor on-stage
444   application.GetGlAbstraction().ClearBoundTextures();
445   application.SendNotification();
446   application.Render();
447
448   // Check that the newActor was rendered
449   DALI_TEST_EQUALS( boundTextures.size(), 1u, TEST_LOCATION );
450   if ( boundTextures.size() )
451   {
452     DALI_TEST_EQUALS( boundTextures[0], expectedTextureId, TEST_LOCATION );
453   }
454
455   // Now remove from stage
456   stage.Remove( newActor );
457
458   // Update & Render with the actor off-stage
459   application.GetGlAbstraction().ClearBoundTextures();
460   application.SendNotification();
461   application.Render();
462   END_TEST;
463 }
464
465 int UtcDaliRenderTaskSetSourceActorEmpty(void)
466 {
467   TestApplication application;
468
469   tet_infoline("Testing RenderTask::SetSourceActor (empty handle case)");
470
471   Stage stage = Stage::GetCurrent();
472
473   const std::vector<GLuint>& boundTextures = application.GetGlAbstraction().GetBoundTextures( GL_TEXTURE0 );
474
475   RenderTaskList taskList = stage.GetRenderTaskList();
476
477   RenderTask task = taskList.GetTask( 0u );
478
479   Actor actor = task.GetSourceActor();
480   DALI_TEST_CHECK( actor );
481
482   std::vector<GLuint> ids;
483   GLuint expectedTextureId( 5 );
484   ids.push_back( expectedTextureId );
485   application.GetGlAbstraction().SetNextTextureIds( ids );
486
487   BitmapImage img = BitmapImage::New( 1,1 );
488   ImageActor newActor = ImageActor::New( img );
489   newActor.SetSize(1,1);
490   stage.Add( newActor );
491
492   Actor nonRenderableActor = Actor::New();
493   stage.Add( nonRenderableActor );
494
495   // Set with empty handle
496   task.SetSourceActor( Actor() );
497   DALI_TEST_CHECK( ! task.GetSourceActor() );
498
499   // Update & Render nothing!
500   application.GetGlAbstraction().ClearBoundTextures();
501   application.SendNotification();
502   application.Render();
503
504   // Check that nothing was rendered
505   DALI_TEST_EQUALS( boundTextures.size(), 0u, TEST_LOCATION );
506
507   // Set with non-empty handle
508   task.SetSourceActor( newActor );
509   DALI_TEST_CHECK( task.GetSourceActor() == newActor );
510
511   // Update & Render the newActor
512   application.GetGlAbstraction().ClearBoundTextures();
513   application.SendNotification();
514   application.Render();
515
516   // Check that the newActor was rendered
517   DALI_TEST_EQUALS( boundTextures.size(), 1u, TEST_LOCATION );
518   if ( boundTextures.size() )
519   {
520     DALI_TEST_EQUALS( boundTextures[0], expectedTextureId, TEST_LOCATION );
521   }
522   END_TEST;
523 }
524
525 int UtcDaliRenderTaskGetSourceActor(void)
526 {
527   TestApplication application;
528
529   tet_infoline("Testing RenderTask::GetSourceActor()");
530
531   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
532
533   RenderTask task = taskList.GetTask( 0u );
534
535   Actor actor = task.GetSourceActor();
536   DALI_TEST_CHECK( actor );
537
538   // By default the entire scene should be rendered
539   Actor root = Stage::GetCurrent().GetLayer( 0 );
540   DALI_TEST_CHECK( root == actor );
541   END_TEST;
542 }
543
544 int UtcDaliRenderTaskSetExclusive(void)
545 {
546   TestApplication application;
547
548   tet_infoline("Testing RenderTask::SetExclusive()");
549
550   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
551
552   // Manipulate the GenTextures behaviour, to identify different ImageActors
553
554   std::vector<GLuint> ids;
555   ids.push_back( 8 ); // 8 = actor1
556   ids.push_back( 9 ); // 9 = actor2
557   ids.push_back( 10 ); // 10 = actor3
558   application.GetGlAbstraction().SetNextTextureIds( ids );
559
560   BitmapImage img1 = BitmapImage::New( 1,1 );
561   ImageActor actor1 = ImageActor::New( img1 );
562   actor1.SetSize(1,1);
563   Stage::GetCurrent().Add( actor1 );
564
565   // Update & Render actor1
566   application.SendNotification();
567   application.Render();
568
569   // Check that the actor1 was rendered
570   const std::vector<GLuint>& boundTextures = application.GetGlAbstraction().GetBoundTextures( GL_TEXTURE0 );
571   DALI_TEST_EQUALS( boundTextures.size(), 1u, TEST_LOCATION );
572
573   if ( boundTextures.size() )
574   {
575     DALI_TEST_EQUALS( boundTextures[0], 8u/*unique to actor1*/, TEST_LOCATION );
576   }
577
578   BitmapImage img2 = BitmapImage::New( 1,1 );
579   ImageActor actor2 = ImageActor::New( img2 );
580   actor2.SetSize(1,1);
581
582   // Force actor2 to be rendered before actor1
583   Layer layer = Layer::New();
584   Stage::GetCurrent().Add( layer );
585   layer.Add( actor2 );
586   layer.LowerToBottom();
587
588   // Update & Render
589   application.GetGlAbstraction().ClearBoundTextures();
590   application.SendNotification();
591   application.Render();
592
593   // Check that the actors were rendered
594   DALI_TEST_EQUALS( boundTextures.size(), 2u, TEST_LOCATION );
595
596   if ( boundTextures.size() )
597   {
598     DALI_TEST_EQUALS( boundTextures[0], 9u/*unique to actor2*/, TEST_LOCATION );
599     DALI_TEST_EQUALS( boundTextures[1], 8u/*unique to actor1*/, TEST_LOCATION );
600   }
601
602   BitmapImage img3 = BitmapImage::New( 1,1 );
603   ImageActor actor3 = ImageActor::New( img3 );
604   actor3.SetSize(1,1);
605
606   // Force actor3 to be rendered before actor2
607   layer = Layer::New();
608   Stage::GetCurrent().Add( layer );
609   layer.Add( actor3 );
610   layer.LowerToBottom();
611
612   // Update & Render all actors
613   application.GetGlAbstraction().ClearBoundTextures();
614   application.SendNotification();
615   application.Render();
616
617   // Check that the actors were rendered
618   DALI_TEST_EQUALS( boundTextures.size(), 3u, TEST_LOCATION );
619
620   if ( boundTextures.size() )
621   {
622     DALI_TEST_EQUALS( boundTextures[0], 10u/*unique to actor3*/, TEST_LOCATION );
623     DALI_TEST_EQUALS( boundTextures[1], 9u/*unique to actor2*/, TEST_LOCATION );
624     DALI_TEST_EQUALS( boundTextures[2], 8u/*unique to actor1*/, TEST_LOCATION );
625   }
626
627   // Both actors are now connected to the root node
628   // Setup 2 render-tasks - the first will render from the root-node, and the second from actor2
629
630   // Not exclusive is the default
631   RenderTask task1 = taskList.GetTask( 0u );
632   DALI_TEST_CHECK( false == task1.IsExclusive() );
633
634   RenderTask task2 = taskList.CreateTask();
635   DALI_TEST_CHECK( false == task2.IsExclusive() );
636   task2.SetSourceActor( actor2 );
637
638   // Task1 should render all actors, and task 2 should render only actor2
639
640   application.GetGlAbstraction().ClearBoundTextures();
641   application.SendNotification();
642   application.Render();
643
644   DALI_TEST_EQUALS( boundTextures.size(), 4u, TEST_LOCATION );
645
646   if ( boundTextures.size() == 4 )
647   {
648     // Test that task 1 renders actor3, then actor2 & then actor1
649     DALI_TEST_CHECK( boundTextures[0] == 10u );
650     DALI_TEST_CHECK( boundTextures[1] == 9u );
651     DALI_TEST_CHECK( boundTextures[2] == 8u );
652
653     // Test that task 2 renders actor2
654     DALI_TEST_EQUALS( boundTextures[3], 9u, TEST_LOCATION );
655   }
656
657   // Make actor2 exclusive to task2
658
659   task2.SetExclusive( true );
660   DALI_TEST_CHECK( true == task2.IsExclusive() );
661
662   // Task1 should render only actor1, and task 2 should render only actor2
663
664   application.GetGlAbstraction().ClearBoundTextures();
665   application.SendNotification();
666   application.Render();
667
668   DALI_TEST_EQUALS( boundTextures.size(), 3u, TEST_LOCATION );
669   if ( boundTextures.size() == 3 )
670   {
671     // Test that task 1 renders actor3 & actor1
672     DALI_TEST_CHECK( boundTextures[0] == 10u );
673     DALI_TEST_CHECK( boundTextures[1] == 8u );
674
675     // Test that task 2 renders actor2
676     DALI_TEST_CHECK( boundTextures[2] == 9u );
677   }
678   END_TEST;
679 }
680
681 int UtcDaliRenderTaskIsExclusive(void)
682 {
683   TestApplication application;
684
685   tet_infoline("Testing RenderTask::IsExclusive()");
686
687   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
688
689   // Not exclusive is the default
690   RenderTask task = taskList.GetTask( 0u );
691   DALI_TEST_CHECK( false == task.IsExclusive() );
692
693   RenderTask newTask = taskList.CreateTask();
694   DALI_TEST_CHECK( false == newTask.IsExclusive() );
695   END_TEST;
696 }
697
698 int UtcDaliRenderTaskSetInputEnabled(void)
699 {
700   TestApplication application;
701
702   tet_infoline("Testing RenderTask::SetInputEnabled()");
703
704   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
705
706   // Input is enabled by default
707   RenderTask task = taskList.GetTask( 0u );
708   DALI_TEST_CHECK( true == task.GetInputEnabled() );
709
710   task.SetInputEnabled( false );
711   DALI_TEST_CHECK( false == task.GetInputEnabled() );
712
713   task.SetInputEnabled( true );
714   DALI_TEST_CHECK( true == task.GetInputEnabled() );
715   END_TEST;
716 }
717
718 int UtcDaliRenderTaskGetInputEnabled(void)
719 {
720   TestApplication application;
721
722   tet_infoline("Testing RenderTask::GetInputEnabled()");
723
724   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
725
726   // Input is enabled by default
727   RenderTask task = taskList.GetTask( 0u );
728   DALI_TEST_CHECK( true == task.GetInputEnabled() );
729
730   RenderTask newTask = taskList.CreateTask();
731   DALI_TEST_CHECK( true == newTask.GetInputEnabled() );
732   END_TEST;
733 }
734
735 int UtcDaliRenderTaskSetCameraActor(void)
736 {
737   TestApplication application;
738
739   tet_infoline("Testing RenderTask::SetCameraActor()");
740
741   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
742
743   RenderTask task = taskList.GetTask( 0u );
744
745   Actor actor = task.GetCameraActor();
746   DALI_TEST_CHECK( actor );
747
748   CameraActor newActor = CameraActor::New();
749   DALI_TEST_CHECK( newActor );
750
751   task.SetCameraActor( newActor );
752   DALI_TEST_CHECK( task.GetCameraActor() != actor );
753   DALI_TEST_CHECK( task.GetCameraActor() == newActor );
754   END_TEST;
755 }
756
757 int UtcDaliRenderTaskGetCameraActor(void)
758 {
759   TestApplication application;
760
761   tet_infoline("Testing RenderTask::GetCameraActor()");
762
763   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
764
765   RenderTask task = taskList.GetTask( 0u );
766
767   Actor actor = task.GetCameraActor();
768   DALI_TEST_CHECK( actor );
769
770   RenderTask newTask = taskList.CreateTask();
771   DALI_TEST_CHECK( actor == newTask.GetCameraActor() );
772   END_TEST;
773 }
774
775 int UtcDaliRenderTaskSetTargetFrameBuffer(void)
776 {
777   TestApplication application;
778
779   tet_infoline("Testing RenderTask::SetTargetFrameBuffer()");
780
781   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
782
783   RenderTask task = taskList.GetTask( 0u );
784
785   // By default render-tasks do not render off-screen
786   FrameBufferImage image = task.GetTargetFrameBuffer();
787   DALI_TEST_CHECK( !image );
788
789   FrameBufferImage newImage = FrameBufferImage::New();
790
791   task.SetTargetFrameBuffer( newImage );
792   DALI_TEST_CHECK( task.GetTargetFrameBuffer() == newImage );
793   END_TEST;
794 }
795
796 int UtcDaliRenderTaskGetTargetFrameBuffer(void)
797 {
798   TestApplication application;
799
800   tet_infoline("Testing RenderTask::GetTargetFrameBuffer()");
801
802   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
803
804   RenderTask task = taskList.GetTask( 0u );
805
806   // By default render-tasks do not render off-screen
807   FrameBufferImage image = task.GetTargetFrameBuffer();
808   DALI_TEST_CHECK( !image );
809
810   RenderTask newTask = taskList.CreateTask();
811   DALI_TEST_CHECK( !newTask.GetTargetFrameBuffer() );
812   END_TEST;
813 }
814
815 int UtcDaliRenderTaskSetScreenToFrameBufferFunction(void)
816 {
817   TestApplication application;
818
819   tet_infoline("Testing RenderTask::SetScreenToFrameBufferFunction()");
820
821   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
822
823   RenderTask task = taskList.GetTask( 0u );
824
825   task.SetScreenToFrameBufferFunction( TestScreenToFrameBufferFunction );
826
827   Vector2 coordinates( 5, 10 );
828   Vector2 convertedCoordinates( 6, 12 ); // + Vector(1, 2)
829
830   RenderTask::ScreenToFrameBufferFunction func = task.GetScreenToFrameBufferFunction();
831   DALI_TEST_CHECK( func( coordinates ) );
832   DALI_TEST_CHECK( coordinates == convertedCoordinates );
833
834   task.SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );
835   func = task.GetScreenToFrameBufferFunction();
836   DALI_TEST_CHECK( func( coordinates ) );
837
838   task.SetScreenToFrameBufferFunction( RenderTask::DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION );
839   func = task.GetScreenToFrameBufferFunction();
840   DALI_TEST_CHECK( ! func( coordinates ) );
841   END_TEST;
842 }
843
844 int UtcDaliRenderTaskGetScreenToFrameBufferFunction(void)
845 {
846   TestApplication application;
847
848   tet_infoline("Testing RenderTask::GetScreenToFrameBufferFunction()");
849
850   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
851
852   RenderTask task = taskList.GetTask( 0u );
853
854   Vector2 originalCoordinates( 5, 10 );
855   Vector2 coordinates( 5, 10 );
856
857   RenderTask::ScreenToFrameBufferFunction func = task.GetScreenToFrameBufferFunction();
858   DALI_TEST_CHECK( !func( coordinates ) ); // conversion should fail by default
859   DALI_TEST_CHECK( coordinates == originalCoordinates ); // coordinates should not be modified
860   END_TEST;
861 }
862
863
864 int UtcDaliRenderTaskGetScreenToFrameBufferMappingActor(void)
865 {
866   TestApplication application;
867   tet_infoline("Testing RenderTask::GetScreenToFrameBufferMappingActor ");
868
869   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
870   RenderTask renderTask = taskList.CreateTask();
871   Actor mappingActor = Actor::New();
872   renderTask.SetScreenToFrameBufferMappingActor(mappingActor);
873
874   DALI_TEST_CHECK( mappingActor == renderTask.GetScreenToFrameBufferMappingActor() );
875   END_TEST;
876 }
877
878 int UtcDaliRenderTaskSetViewport(void)
879 {
880   TestApplication application;
881
882   tet_infoline("Testing RenderTask::SetViewport()");
883
884   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
885
886   RenderTask task = taskList.GetTask( 0u );
887
888   Viewport viewport = task.GetViewport();
889
890   // By default the viewport should match the stage width/height
891
892   Vector2 stageSize = Stage::GetCurrent().GetSize();
893   Viewport expectedViewport( 0, 0, stageSize.width, stageSize.height );
894   DALI_TEST_CHECK( viewport == expectedViewport );
895
896   Viewport newViewport( 0, 0, stageSize.width * 0.5f, stageSize.height * 0.5f );
897   task.SetViewport( newViewport );
898
899   // Update (viewport is a property)
900   application.SendNotification();
901   application.Render();
902
903   DALI_TEST_CHECK( task.GetViewport() == newViewport );
904   END_TEST;
905 }
906
907 int UtcDaliRenderTaskGetViewport(void)
908 {
909   TestApplication application;
910
911   tet_infoline("Testing RenderTask::GetViewport()");
912
913   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
914
915   RenderTask task = taskList.GetTask( 0u );
916
917   Viewport viewport = task.GetViewport();
918
919   // By default the viewport should match the stage width/height
920
921   Vector2 stageSize = Stage::GetCurrent().GetSize();
922   Viewport expectedViewport( 0, 0, stageSize.width, stageSize.height );
923   DALI_TEST_CHECK( viewport == expectedViewport );
924
925   RenderTask newTask = taskList.CreateTask();
926   DALI_TEST_CHECK( newTask.GetViewport() == expectedViewport );
927   END_TEST;
928 }
929
930 int UtcDaliRenderTaskSetViewportPosition(void)
931 {
932   TestApplication application;
933
934   tet_infoline("Testing RenderTask::SetViewportPosition()");
935
936   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
937
938   RenderTask task = taskList.GetTask( 0u );
939
940   Viewport viewport = task.GetViewport();
941
942   // By default the viewport should match the stage width/height
943
944   Vector2 stageSize = Stage::GetCurrent().GetSize();
945   Viewport expectedViewport( 0, 0, stageSize.width, stageSize.height );
946   DALI_TEST_CHECK( viewport == expectedViewport );
947
948   // 'Setter' test
949   Vector2 newPosition(25.0f, 50.0f);
950   task.SetViewportPosition( newPosition );
951
952   // Update (viewport is a property)
953   application.SendNotification();
954   application.Render();
955
956   DALI_TEST_EQUALS( task.GetCurrentViewportPosition(), newPosition, Math::MACHINE_EPSILON_1, TEST_LOCATION );
957
958   // Set by Property test
959   Vector2 newPosition2(32.0f, 32.0f);
960   task.SetProperty( RenderTask::VIEWPORT_POSITION, newPosition2 );
961
962   // Update
963   application.SendNotification();
964   application.Render();
965
966   DALI_TEST_EQUALS( task.GetCurrentViewportPosition(), newPosition2, Math::MACHINE_EPSILON_1, TEST_LOCATION );
967
968   Vector2 newPosition3(64.0f, 0.0f);
969   Animation animation = Animation::New(1.0f);
970   animation.AnimateTo( Property( task, RenderTask::VIEWPORT_POSITION ), newPosition3, AlphaFunctions::Linear );
971   animation.Play();
972
973   // Perform 1000ms worth of updates at which point animation should have completed.
974   Wait(application, 1000);
975   DALI_TEST_EQUALS( task.GetCurrentViewportPosition(), newPosition3, Math::MACHINE_EPSILON_1, TEST_LOCATION );
976   END_TEST;
977 }
978
979 int UtcDaliRenderTaskSetViewportSize(void)
980 {
981   TestApplication application;
982
983   tet_infoline("Testing RenderTask::SetViewportSize()");
984
985   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
986
987   RenderTask task = taskList.GetTask( 0u );
988
989   Viewport viewport = task.GetViewport();
990
991   // By default the viewport should match the stage width/height
992
993   Vector2 stageSize = Stage::GetCurrent().GetSize();
994   Viewport expectedViewport( 0, 0, stageSize.width, stageSize.height );
995   DALI_TEST_CHECK( viewport == expectedViewport );
996
997   Vector2 newSize(128.0f, 64.0f);
998   task.SetViewportSize( newSize );
999
1000   // Update (viewport is a property)
1001   application.SendNotification();
1002   application.Render();
1003
1004   DALI_TEST_EQUALS( task.GetCurrentViewportSize(), newSize, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1005
1006   // Set by Property test
1007   Vector2 newSize2(50.0f, 50.0f);
1008   task.SetProperty( RenderTask::VIEWPORT_SIZE, newSize2 );
1009
1010   // Update
1011   application.SendNotification();
1012   application.Render();
1013
1014   DALI_TEST_EQUALS( task.GetCurrentViewportSize(), newSize2, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1015
1016   Vector2 newSize3(10.0f, 10.0f);
1017   Animation animation = Animation::New(1.0f);
1018   animation.AnimateTo( Property( task, RenderTask::VIEWPORT_SIZE ), newSize3, AlphaFunctions::Linear );
1019   animation.Play();
1020
1021   // Perform 1000ms worth of updates at which point animation should have completed.
1022   Wait(application, 1000);
1023   DALI_TEST_EQUALS( task.GetCurrentViewportSize(), newSize3, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1024
1025   END_TEST;
1026 }
1027
1028 int UtcDaliRenderTaskSetClearColor(void)
1029 {
1030   TestApplication application;
1031
1032   tet_infoline("Testing RenderTask::SetClearColor()");
1033
1034   Vector4 testColor( 1.0f, 2.0f, 3.0f, 4.0f );
1035   Vector4 testColor2( 5.0f, 6.0f, 7.0f, 8.0f );
1036
1037   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1038
1039   RenderTask task = taskList.GetTask( 0u );
1040   DALI_TEST_CHECK( task.GetClearColor() != testColor );
1041
1042   task.SetClearColor( testColor );
1043
1044   // Wait a frame.
1045   Wait(application);
1046
1047   DALI_TEST_EQUALS( task.GetClearColor(), testColor, TEST_LOCATION );
1048
1049   task.SetProperty( RenderTask::CLEAR_COLOR, testColor2 );
1050
1051   // Wait a frame.
1052   Wait(application);
1053
1054   DALI_TEST_EQUALS( task.GetClearColor(), testColor2, TEST_LOCATION );
1055   END_TEST;
1056 }
1057
1058 int UtcDaliRenderTaskGetClearColor(void)
1059 {
1060   TestApplication application;
1061
1062   tet_infoline("Testing RenderTask::GetClearColor()");
1063
1064   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1065   RenderTask task = taskList.GetTask( 0u );
1066   DALI_TEST_EQUALS( task.GetClearColor(), RenderTask::DEFAULT_CLEAR_COLOR, TEST_LOCATION );
1067   END_TEST;
1068 }
1069
1070 int UtcDaliRenderTaskSetClearEnabled(void)
1071 {
1072   TestApplication application;
1073
1074   tet_infoline("Testing RenderTask::SetClearEnabled()");
1075
1076   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1077
1078   RenderTask task = taskList.GetTask( 0u );
1079   DALI_TEST_CHECK( !task.GetClearEnabled() ); // defaults to false
1080
1081   task.SetClearEnabled( true );
1082   DALI_TEST_EQUALS( task.GetClearEnabled(), true, TEST_LOCATION );
1083
1084   task.SetClearEnabled( false );
1085   DALI_TEST_EQUALS( task.GetClearEnabled(), false, TEST_LOCATION );
1086   END_TEST;
1087 }
1088
1089 int UtcDaliRenderTaskGetClearEnabled(void)
1090 {
1091   TestApplication application;
1092
1093   tet_infoline("Testing RenderTask::GetClearEnabled()");
1094
1095   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1096
1097   RenderTask task = taskList.GetTask( 0u );
1098   DALI_TEST_CHECK( !task.GetClearEnabled() ); // defaults to false
1099   END_TEST;
1100 }
1101
1102 int UtcDaliRenderTaskSetRefreshRate(void)
1103 {
1104   TestApplication application;
1105
1106   tet_infoline("Testing RenderTask::SetRefreshRate()");
1107
1108   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1109
1110   // By default tasks will be processed every frame
1111   RenderTask task = taskList.GetTask( 0u );
1112   DALI_TEST_CHECK( RenderTask::REFRESH_ALWAYS == task.GetRefreshRate() );
1113
1114   task.SetRefreshRate( 2u ); // every-other frame
1115   DALI_TEST_CHECK( 2u == task.GetRefreshRate() );
1116
1117   task.SetRefreshRate( RenderTask::REFRESH_ALWAYS );
1118   DALI_TEST_CHECK( RenderTask::REFRESH_ALWAYS == task.GetRefreshRate() );
1119   END_TEST;
1120 }
1121
1122 int UtcDaliRenderTaskGetRefreshRate(void)
1123 {
1124   TestApplication application;
1125
1126   tet_infoline("Testing RenderTask::GetRefreshRate()");
1127
1128   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1129
1130   // By default tasks will be processed every frame
1131   RenderTask task = taskList.GetTask( 0u );
1132   DALI_TEST_CHECK( RenderTask::REFRESH_ALWAYS == task.GetRefreshRate() );
1133
1134   RenderTask newTask = taskList.CreateTask();
1135   DALI_TEST_CHECK( RenderTask::REFRESH_ALWAYS == newTask.GetRefreshRate() );
1136   END_TEST;
1137 }
1138
1139 int UtcDaliRenderTaskSignalFinished(void)
1140 {
1141   TestApplication application;
1142
1143   tet_infoline("Testing RenderTask::SignalFinished()");
1144
1145   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1146   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
1147
1148   CameraActor offscreenCameraActor = CameraActor::New();
1149
1150   Stage::GetCurrent().Add( offscreenCameraActor );
1151
1152   BitmapImage image = BitmapImage::New( 10, 10 );
1153   ImageActor rootActor = ImageActor::New( image );
1154   rootActor.SetSize( 10, 10 );
1155   Stage::GetCurrent().Add( rootActor );
1156
1157   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1158   NativeImagePtr testNativeImagePtr = new TestNativeImage(10, 10);
1159   FrameBufferImage frameBufferImage = FrameBufferImage::New( *testNativeImagePtr.Get() );
1160
1161   // Flush all outstanding messages
1162   application.SendNotification();
1163   application.Render();
1164
1165   RenderTask newTask = taskList.CreateTask();
1166   newTask.SetCameraActor( offscreenCameraActor );
1167   newTask.SetSourceActor( rootActor );
1168   newTask.SetInputEnabled( false );
1169   newTask.SetClearColor( Vector4( 0.f, 0.f, 0.f, 0.f ) );
1170   newTask.SetClearEnabled( true );
1171   newTask.SetExclusive( true );
1172   newTask.SetRefreshRate( RenderTask::REFRESH_ONCE );
1173   newTask.SetTargetFrameBuffer( frameBufferImage );
1174
1175   // Framebuffer doesn't actually get created until Connected, i.e. by previous line
1176
1177   bool finished = false;
1178   RenderTaskFinished renderTaskFinished( finished );
1179   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1180
1181   // Flush the queue and render.
1182   application.SendNotification();
1183
1184   // 1 render to process render task, then wait for sync before finished msg is sent
1185   // from update to the event thread.
1186
1187   application.Render();
1188   application.SendNotification();
1189   DALI_TEST_CHECK( !finished );
1190
1191   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
1192   DALI_TEST_CHECK( lastSyncObj != NULL );
1193
1194   application.Render();
1195   DALI_TEST_EQUALS( (application.GetUpdateStatus() & Integration::KeepUpdating::RENDER_TASK_SYNC), Integration::KeepUpdating::RENDER_TASK_SYNC, TEST_LOCATION );
1196   application.SendNotification();
1197   DALI_TEST_CHECK( !finished );
1198
1199   application.Render();
1200   DALI_TEST_EQUALS( (application.GetUpdateStatus() & Integration::KeepUpdating::RENDER_TASK_SYNC), Integration::KeepUpdating::RENDER_TASK_SYNC, TEST_LOCATION );
1201   application.SendNotification();
1202   DALI_TEST_CHECK( ! finished );
1203
1204   sync.SetObjectSynced( lastSyncObj, true );
1205
1206   application.Render();
1207   application.SendNotification();
1208   DALI_TEST_CHECK( !finished );
1209
1210   application.Render();
1211   application.SendNotification();
1212   DALI_TEST_CHECK( finished );
1213   finished = false;
1214
1215   application.Render(); // Double check no more finished signal
1216   application.SendNotification();
1217   DALI_TEST_CHECK( ! finished );
1218   END_TEST;
1219 }
1220
1221
1222 int UtcDaliRenderTaskContinuous01(void)
1223 {
1224   TestApplication application;
1225
1226   tet_infoline("Testing RenderTask Render Continuous using loading image\nPRE: render task not ready (source actor not staged)\nPOST:continuous renders, no Finished signal");
1227
1228   // SETUP AN OFFSCREEN RENDER TASK
1229   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1230   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1231   drawTrace.Enable(true);
1232
1233   Actor rootActor = Actor::New();
1234   Stage::GetCurrent().Add( rootActor );
1235
1236   CameraActor offscreenCameraActor = CameraActor::New();
1237   Stage::GetCurrent().Add( offscreenCameraActor );
1238
1239   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1240   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1241   Integration::ResourceId imageRequestId = imageRequest->GetId();
1242   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1243
1244   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1245   bool finished = false;
1246   RenderTaskFinished renderTaskFinished( finished );
1247   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1248   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1249   application.SendNotification();
1250
1251   // START PROCESS/RENDER                     Input,    Expected  Input, Expected, KeepUpdating
1252   DALI_TEST_CHECK( UpdateRender(application,  drawTrace, false,   finished, false, true ) );
1253   application.GetPlatform().ClearReadyResources();
1254
1255   DALI_TEST_CHECK( UpdateRender(application,  drawTrace, false,   finished, false, false ) );
1256
1257   // ADD SOURCE ACTOR TO STAGE - expect continuous renders to start, no finished signal
1258   Stage::GetCurrent().Add(secondRootActor);
1259   application.SendNotification();
1260
1261   // CONTINUE PROCESS/RENDER                  Input,    Expected  Input,    Expected
1262   DALI_TEST_CHECK( UpdateRender(application,  drawTrace, true,    finished, false, true ) );
1263   DALI_TEST_CHECK( UpdateRender(application,  drawTrace, true,    finished, false, false ) );
1264   END_TEST;
1265 }
1266
1267
1268 int UtcDaliRenderTaskContinuous02(void)
1269 {
1270   TestApplication application;
1271
1272   tet_infoline("Testing RenderTask Render Continuous using loading image\nPRE: render task not ready (source actor not visible)\nPOST:continuous renders, no Finished signal");
1273
1274   // SETUP AN OFFSCREEN RENDER TASK
1275   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1276   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1277   drawTrace.Enable(true);
1278
1279   Actor rootActor = Actor::New();
1280   Stage::GetCurrent().Add( rootActor );
1281
1282   CameraActor offscreenCameraActor = CameraActor::New();
1283   Stage::GetCurrent().Add( offscreenCameraActor );
1284
1285   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1286   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1287   Integration::ResourceId imageRequestId = imageRequest->GetId();
1288   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1289   Stage::GetCurrent().Add(secondRootActor);
1290   secondRootActor.SetVisible(false);
1291
1292   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1293   bool finished = false;
1294   RenderTaskFinished renderTaskFinished( finished );
1295   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1296   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1297   application.SendNotification();
1298
1299   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1300   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1301   application.GetPlatform().ClearReadyResources();
1302   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, false ) );
1303
1304   // MAKE SOURCE ACTOR VISIBLE - expect continuous renders to start, no finished signal
1305   secondRootActor.SetVisible(true);
1306   application.SendNotification();
1307
1308   // CONTINUE PROCESS/RENDER                 Input,    Expected  Input,    Expected
1309   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1310   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false ) );
1311   END_TEST;
1312 }
1313
1314 int UtcDaliRenderTaskContinuous03(void)
1315 {
1316   TestApplication application;
1317
1318   tet_infoline("Testing RenderTask Render Continuous using loading image\nPRE: render task not ready (camera actor not staged)\nPOST:continuous renders, no Finished signal");
1319
1320   // SETUP AN OFFSCREEN RENDER TASK
1321   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1322   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1323   drawTrace.Enable(true);
1324
1325   Actor rootActor = Actor::New();
1326   Stage::GetCurrent().Add( rootActor );
1327
1328   CameraActor offscreenCameraActor = CameraActor::New();
1329   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1330   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1331   Integration::ResourceId imageRequestId = imageRequest->GetId();
1332   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1333   Stage::GetCurrent().Add(secondRootActor);
1334
1335   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1336   bool finished = false;
1337   RenderTaskFinished renderTaskFinished( finished );
1338   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1339   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1340   application.SendNotification();
1341
1342   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1343   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1344   application.GetPlatform().ClearReadyResources();
1345   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, false ) );
1346
1347   // ADD CAMERA ACTOR TO STAGE - expect continuous renders to start, no finished signal
1348   Stage::GetCurrent().Add( offscreenCameraActor );
1349   application.SendNotification();
1350
1351   // CONTINUE PROCESS/RENDER                 Input,    Expected  Input,    Expected
1352   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1353   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false ) );
1354   END_TEST;
1355 }
1356
1357
1358 int UtcDaliRenderTaskContinuous04(void)
1359 {
1360   TestApplication application;
1361
1362   tet_infoline("Testing RenderTask Render Continuous using loading image\nPRE: Resource not ready\nPOST:continuous renders, no Finished signal");
1363
1364   // SETUP AN OFFSCREEN RENDER TASK
1365   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1366   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1367   drawTrace.Enable(true);
1368
1369   Actor rootActor = Actor::New();
1370   Stage::GetCurrent().Add( rootActor );
1371
1372   CameraActor offscreenCameraActor = CameraActor::New();
1373   Stage::GetCurrent().Add( offscreenCameraActor );
1374   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1375   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1376   Integration::ResourceId imageRequestId = imageRequest->GetId();
1377   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1378   Stage::GetCurrent().Add(secondRootActor);
1379
1380   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1381   bool finished = false;
1382   RenderTaskFinished renderTaskFinished( finished );
1383   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1384   application.SendNotification();
1385
1386   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1387   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1388   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1389
1390   // FINISH RESOURCE LOADING - expect 'continuous' renders to start, no finished signal
1391   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1392   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false ) );
1393   END_TEST;
1394 }
1395
1396
1397 int UtcDaliRenderTaskOnce01(void)
1398 {
1399   TestApplication application;
1400
1401   tet_infoline("Testing RenderTask Render Once GlSync, using loading image\nPRE: Resources not ready, Source not visible\nPOST: Finished signal sent once only");
1402
1403   // SETUP AN OFFSCREEN RENDER TASK
1404   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1405   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
1406   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1407   drawTrace.Enable(true);
1408
1409   Actor rootActor = Actor::New();
1410   Stage::GetCurrent().Add( rootActor );
1411
1412   CameraActor offscreenCameraActor = CameraActor::New();
1413   Stage::GetCurrent().Add( offscreenCameraActor );
1414   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1415   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1416   Integration::ResourceId imageRequestId = imageRequest->GetId();
1417   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1418
1419   Stage::GetCurrent().Add(secondRootActor);
1420   secondRootActor.SetVisible(false);
1421
1422   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, true);
1423   bool finished = false;
1424   RenderTaskFinished renderTaskFinished( finished );
1425   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1426   application.SendNotification();
1427
1428   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1429   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1430   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1431
1432   // MAKE SOURCE VISIBLE
1433   secondRootActor.SetVisible(true);
1434   application.SendNotification();
1435   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1436   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1437
1438   // FINISH RESOURCE LOADING - expect no rendering yet
1439   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1440   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1441   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
1442   DALI_TEST_CHECK( lastSyncObj != NULL );
1443
1444   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1445   application.GetPlatform().ClearReadyResources();
1446   sync.SetObjectSynced( lastSyncObj, true );
1447   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,   finished, false, true  ) );
1448   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false  ) );
1449   END_TEST;
1450 }
1451
1452 int UtcDaliRenderTaskOnce02(void)
1453 {
1454   TestApplication application;
1455
1456   tet_infoline("Testing RenderTask Render Once GlSync, using loading image. Switch from render always after ready to render once\n"
1457                "PRE: Render task ready, Image not loaded\n"
1458                "POST: Finished signal sent only once");
1459
1460   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
1461   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1462   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
1463   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1464   drawTrace.Enable(true);
1465
1466   Actor rootActor = Actor::New();
1467   Stage::GetCurrent().Add( rootActor );
1468
1469   CameraActor offscreenCameraActor = CameraActor::New();
1470   Stage::GetCurrent().Add( offscreenCameraActor );
1471   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1472   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1473   Integration::ResourceId imageRequestId = imageRequest->GetId();
1474   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1475   Stage::GetCurrent().Add(secondRootActor);
1476
1477   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1478   bool finished = false;
1479   RenderTaskFinished renderTaskFinished( finished );
1480   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1481   application.SendNotification();
1482
1483   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1484   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
1485   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
1486
1487   // FINISH RESOURCE LOADING
1488   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1489   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false ) );
1490   application.GetPlatform().ClearReadyResources();
1491   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false ) );
1492
1493   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
1494   application.SendNotification(); //         Input,    Expected  Input,    Expected
1495   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1496   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
1497   DALI_TEST_CHECK( lastSyncObj != NULL );
1498
1499   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1500   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1501   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1502   sync.SetObjectSynced( lastSyncObj, true );
1503   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true  ) );
1504   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false  ) );
1505
1506   END_TEST;
1507 }
1508
1509
1510 int UtcDaliRenderTaskOnce03(void)
1511 {
1512   TestApplication application;
1513
1514   tet_infoline("Testing RenderTask Render Once GlSync\n"
1515                "Switch from Render always after ready to render once with resources unready\n"
1516                "PRE: Everything ready to render\n"
1517                "POST: Finished signal sent once");
1518
1519   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
1520   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1521   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
1522   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1523   drawTrace.Enable(true);
1524
1525   Actor rootActor = Actor::New();
1526   Stage::GetCurrent().Add( rootActor );
1527
1528   CameraActor offscreenCameraActor = CameraActor::New();
1529   Stage::GetCurrent().Add( offscreenCameraActor );
1530   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1531   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1532   Integration::ResourceId imageRequestId = imageRequest->GetId();
1533   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1534   Stage::GetCurrent().Add(secondRootActor);
1535
1536   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1537   bool finished = false;
1538   RenderTaskFinished renderTaskFinished( finished );
1539   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1540   application.SendNotification();
1541
1542   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1543   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
1544   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
1545
1546   // CHANGE TO RENDER ONCE
1547   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
1548   application.SendNotification(); //         Input,    Expected  Input,    Expected
1549   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
1550   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
1551
1552   // FINISH RESOURCE LOADING
1553   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1554   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1555   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
1556   DALI_TEST_CHECK( lastSyncObj != NULL );
1557   application.GetPlatform().ClearReadyResources();
1558
1559   sync.SetObjectSynced( lastSyncObj, true );
1560   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true  ) );
1561   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false  ) );
1562
1563   END_TEST;
1564 }
1565
1566 #if 0
1567 //int UtcDaliRenderTaskOnce04(void)
1568 {
1569   TestApplication application;
1570
1571   tet_infoline("Testing RenderTask Render Once GlSync\n"
1572                "During RenderOnce, make ready resources unready before sending first finished signal\n"
1573                "PRE: Everything ready.\n"
1574                "POST: Finished signal sent only once");
1575
1576   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
1577   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1578   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
1579   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1580   drawTrace.Enable(true);
1581
1582   Actor rootActor = Actor::New();
1583   Stage::GetCurrent().Add( rootActor );
1584
1585   CameraActor offscreenCameraActor = CameraActor::New();
1586   Stage::GetCurrent().Add( offscreenCameraActor );
1587   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1588   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1589   Integration::ResourceId imageRequestId = imageRequest->GetId();
1590   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1591   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1592   application.Render();
1593
1594   Stage::GetCurrent().Add(secondRootActor);
1595   application.GetPlatform().ClearReadyResources();
1596
1597   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1598   bool finished = false;
1599   RenderTaskFinished renderTaskFinished( finished );
1600   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1601   application.SendNotification();
1602
1603   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1604   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1605   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1606
1607   // CHANGE TO RENDER ONCE, RESOURCES BECOME NOT READY
1608   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
1609
1610   // Doesn't work...
1611   ReloadImage(application, secondRootActor.GetImage());
1612   application.SendNotification(); //         Input,    Expected  Input,    Expected
1613
1614   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
1615   DALI_TEST_EQUALS( secondRootActor.GetImage().GetLoadingState(), Dali::ResourceLoading, TEST_LOCATION);
1616   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
1617
1618   // FINISH RESOURCE LOADING
1619   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1620   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1621   application.GetPlatform().ClearReadyResources();
1622   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
1623   DALI_TEST_CHECK( lastSyncObj != NULL );
1624
1625   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1626   sync.SetObjectSynced( lastSyncObj, true );
1627   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true  ) );
1628   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, true  ) );
1629
1630   // Finished rendering - expect no more renders, no more signals:
1631   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1632   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1633   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1634   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1635   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1636   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1637   END_TEST;
1638 }
1639 #endif
1640
1641 int UtcDaliRenderTaskOnce05(void)
1642 {
1643   TestApplication application;
1644
1645   tet_infoline("Testing RenderTask Render Once GLSync\n"
1646                "Render once, Second call to SetRefreshRate(ONCE) triggers only one more finished signal\n"
1647                "PRE: Everything ready\n"
1648                "POST: exactly 1 finished signal per call to SetRefreshRate(ONCE)");
1649
1650   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
1651   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1652   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
1653   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1654   drawTrace.Enable(true);
1655
1656   Actor rootActor = Actor::New();
1657   Stage::GetCurrent().Add( rootActor );
1658
1659   CameraActor offscreenCameraActor = CameraActor::New();
1660   Stage::GetCurrent().Add( offscreenCameraActor );
1661   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1662   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1663   Integration::ResourceId imageRequestId = imageRequest->GetId();
1664   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1665   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1666   application.Render();
1667   application.GetPlatform().ClearReadyResources();
1668
1669   Stage::GetCurrent().Add(secondRootActor);
1670
1671   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1672   bool finished = false;
1673   RenderTaskFinished renderTaskFinished( finished );
1674   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1675   application.SendNotification();
1676
1677   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1678   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1679   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false ) );
1680
1681   // CHANGE TO RENDER ONCE,
1682   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
1683   application.SendNotification();
1684   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1685   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
1686   DALI_TEST_CHECK( lastSyncObj != NULL );
1687
1688   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1689   sync.SetObjectSynced( lastSyncObj, true );
1690   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1691   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false  ) );
1692
1693   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
1694   application.SendNotification();
1695   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1696   lastSyncObj = sync.GetLastSyncObject();
1697   DALI_TEST_CHECK( lastSyncObj != NULL );
1698
1699   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1700   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1701   sync.SetObjectSynced( lastSyncObj, true );
1702   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1703   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false  ) );
1704   END_TEST;
1705 }
1706
1707 int UtcDaliRenderTaskOnce06(void)
1708 {
1709   TestApplication application;
1710
1711   tet_infoline("Testing RenderTask Render Once GLSync\n"
1712                "Render once, Call to SetRefreshRate(ONCE) in Finished signal callback triggers "
1713                "another render & another finished signal\n"
1714                "PRE: Everything ready\n"
1715                "POST: exactly 1 finished signal per call to SetRefreshRate(ONCE)");
1716
1717
1718   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
1719   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1720   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
1721   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1722   drawTrace.Enable(true);
1723
1724   Actor rootActor = Actor::New();
1725   Stage::GetCurrent().Add( rootActor );
1726
1727   CameraActor offscreenCameraActor = CameraActor::New();
1728   Stage::GetCurrent().Add( offscreenCameraActor );
1729   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1730   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1731   Integration::ResourceId imageRequestId = imageRequest->GetId();
1732   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1733   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1734   application.Render();
1735   application.GetPlatform().ClearReadyResources();
1736
1737   Stage::GetCurrent().Add(secondRootActor);
1738
1739   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1740   bool finished = false;
1741
1742   ConnectionTracker connectionTracker;
1743   RenderTaskFinishedRenderAgain renderTaskFinishedRenderAgain( finished );
1744   newTask.FinishedSignal().Connect( &connectionTracker, renderTaskFinishedRenderAgain );
1745
1746   application.SendNotification();
1747
1748   // Expect 2 frames to be drawn.
1749   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1750   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1751   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
1752   DALI_TEST_CHECK( lastSyncObj == NULL );
1753   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false ) );
1754
1755   // CHANGE TO RENDER ONCE,
1756   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
1757   application.SendNotification();
1758   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1759   lastSyncObj = sync.GetLastSyncObject();
1760   DALI_TEST_CHECK( lastSyncObj != NULL );
1761
1762   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1763   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1764
1765   sync.SetObjectSynced( lastSyncObj, true );
1766   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1767   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false  ) );
1768   application.SendNotification();
1769
1770   // Expect SetRefreshRate to have been called again
1771   // Prevent next finished signal calling refresh once again
1772   RenderTaskFinished renderTaskFinished( finished );
1773   connectionTracker.DisconnectAll();
1774   newTask.FinishedSignal().Connect( &connectionTracker, renderTaskFinished );
1775   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1776   lastSyncObj = sync.GetLastSyncObject();
1777   DALI_TEST_CHECK( lastSyncObj != NULL );
1778
1779   sync.SetObjectSynced( lastSyncObj, true );
1780   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1781   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false  ) );
1782   END_TEST;
1783 }
1784
1785
1786 int UtcDaliRenderTaskOnce07(void)
1787 {
1788   TestApplication application;
1789
1790   tet_infoline("Testing RenderTask Render Once GlSync\n"
1791                "SetRefreshRate(ONCE) again before first finished signal has been sent.\n"
1792                "PRE: resources ready\n"
1793                "POST: Only 1 finished signal sent.");
1794
1795   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
1796   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1797   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
1798   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1799   drawTrace.Enable(true);
1800
1801   Actor rootActor = Actor::New();
1802   Stage::GetCurrent().Add( rootActor );
1803
1804   CameraActor offscreenCameraActor = CameraActor::New();
1805   Stage::GetCurrent().Add( offscreenCameraActor );
1806   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1807   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1808   Integration::ResourceId imageRequestId = imageRequest->GetId();
1809   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1810   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1811   application.Render();
1812   application.GetPlatform().ClearReadyResources();
1813
1814   Stage::GetCurrent().Add(secondRootActor);
1815
1816   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1817   bool finished = false;
1818   RenderTaskFinished renderTaskFinished( finished );
1819   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1820   application.SendNotification();
1821
1822   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1823   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1824   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false ) );
1825
1826   // CHANGE TO RENDER ONCE,
1827   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
1828   application.SendNotification();
1829   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1830   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1831   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1832
1833   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
1834   application.SendNotification();
1835   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1836   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
1837   DALI_TEST_CHECK( lastSyncObj != NULL );
1838
1839   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1840   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1841   sync.SetObjectSynced( lastSyncObj, true );
1842   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1843   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false  ) );
1844
1845   END_TEST;
1846 }
1847
1848
1849
1850 int UtcDaliRenderTaskOnce08(void)
1851 {
1852   TestApplication application;
1853
1854   tet_infoline("Testing RenderTask Render Once GlSync\n"
1855                "SetRefreshRate(ONCE), resource load failed completes render task.\n"
1856                "PRE: resources not ready\n"
1857                "POST: Only 1 finished signal sent.");
1858
1859   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
1860   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1861   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
1862   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1863   drawTrace.Enable(true);
1864
1865   Actor rootActor = Actor::New();
1866   Stage::GetCurrent().Add( rootActor );
1867
1868   CameraActor offscreenCameraActor = CameraActor::New();
1869   Stage::GetCurrent().Add( offscreenCameraActor );
1870   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1871   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1872   Integration::ResourceId imageRequestId = imageRequest->GetId();
1873   Stage::GetCurrent().Add(secondRootActor);
1874
1875   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1876   bool finished = false;
1877   RenderTaskFinished renderTaskFinished( finished );
1878   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1879   application.SendNotification();
1880
1881   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1882   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
1883   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
1884
1885   // CHANGE TO RENDER ONCE,
1886   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
1887   application.SendNotification();
1888   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
1889   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
1890   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
1891
1892   tet_printf("  FailImageLoad\n");
1893
1894   FailImageLoad(application, imageRequestId); // Need to run Update again for this to complete
1895   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) ); // nothing to draw
1896   application.SendNotification();
1897
1898   // Drawing empty framebuffer, so will still get a GL sync
1899   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
1900   DALI_TEST_CHECK( lastSyncObj != NULL );
1901
1902   // Expect finished signal, as all resources are complete
1903   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,   finished, true, false ) );
1904
1905   END_TEST;
1906 }
1907
1908
1909
1910 int UtcDaliRenderTaskOnceNoSync01(void)
1911 {
1912   TestApplication application;
1913
1914   tet_infoline("Testing RenderTask Render Once, using loading image\nPRE: Resources not ready, Source not visible\nPOST: Finished signal sent once only");
1915
1916   // SETUP AN OFFSCREEN RENDER TASK
1917   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1918   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1919   drawTrace.Enable(true);
1920
1921   Actor rootActor = Actor::New();
1922   Stage::GetCurrent().Add( rootActor );
1923
1924   CameraActor offscreenCameraActor = CameraActor::New();
1925   Stage::GetCurrent().Add( offscreenCameraActor );
1926   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1927   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1928   Integration::ResourceId imageRequestId = imageRequest->GetId();
1929   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1930
1931   Stage::GetCurrent().Add(secondRootActor);
1932   secondRootActor.SetVisible(false);
1933
1934   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, false);
1935   bool finished = false;
1936   RenderTaskFinished renderTaskFinished( finished );
1937   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1938   application.SendNotification();
1939
1940   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1941   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1942   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1943
1944   // MAKE SOURCE VISIBLE
1945   secondRootActor.SetVisible(true);
1946   application.SendNotification();
1947   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1948   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1949
1950   // FINISH RESOURCE LOADING - expect immediate rendering yet
1951   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1952   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1953   application.GetPlatform().ClearReadyResources();
1954   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false ) );
1955   END_TEST;
1956 }
1957
1958 int UtcDaliRenderTaskOnceNoSync02(void)
1959 {
1960   TestApplication application;
1961
1962   tet_infoline("Testing RenderTask Render Once, using loading image. Switch from render always after ready to render once\n"
1963                "PRE: Render task ready, Image not loaded\n"
1964                "POST: Finished signal sent only once");
1965
1966   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
1967   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1968   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1969   drawTrace.Enable(true);
1970
1971   Actor rootActor = Actor::New();
1972   Stage::GetCurrent().Add( rootActor );
1973
1974   CameraActor offscreenCameraActor = CameraActor::New();
1975   Stage::GetCurrent().Add( offscreenCameraActor );
1976   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1977   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1978   Integration::ResourceId imageRequestId = imageRequest->GetId();
1979   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1980   Stage::GetCurrent().Add(secondRootActor);
1981
1982   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
1983   bool finished = false;
1984   RenderTaskFinished renderTaskFinished( finished );
1985   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1986   application.SendNotification();
1987
1988   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1989   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1990   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1991
1992   // FINISH RESOURCE LOADING
1993   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1994   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false ) );
1995   application.GetPlatform().ClearReadyResources();
1996
1997   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
1998   application.SendNotification(); //         Input,    Expected  Input,    Expected
1999   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
2000   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false  ) );
2001   END_TEST;
2002 }
2003
2004
2005 int UtcDaliRenderTaskOnceNoSync03(void)
2006 {
2007   TestApplication application;
2008
2009   tet_infoline("Testing RenderTask Render Once\n"
2010                "Switch from Render always after ready to render once with resources unready\n"
2011                "PRE: Everything ready to render\n"
2012                "POST: Finished signal sent once");
2013
2014   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2015   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2016   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2017   drawTrace.Enable(true);
2018
2019   Actor rootActor = Actor::New();
2020   Stage::GetCurrent().Add( rootActor );
2021
2022   CameraActor offscreenCameraActor = CameraActor::New();
2023   Stage::GetCurrent().Add( offscreenCameraActor );
2024   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
2025   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2026   Integration::ResourceId imageRequestId = imageRequest->GetId();
2027   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2028   Stage::GetCurrent().Add(secondRootActor);
2029
2030   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2031   bool finished = false;
2032   RenderTaskFinished renderTaskFinished( finished );
2033   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2034   application.SendNotification();
2035
2036   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2037   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
2038   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
2039
2040   // CHANGE TO RENDER ONCE
2041   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2042   application.SendNotification(); //         Input,    Expected  Input,    Expected
2043   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
2044   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
2045
2046   // FINISH RESOURCE LOADING
2047   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2048   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
2049   application.GetPlatform().ClearReadyResources();
2050   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false  ) );
2051   END_TEST;
2052 }
2053
2054 #if 0
2055 //int UtcDaliRenderTaskOnceNoSync04(void)
2056 {
2057   TestApplication application;
2058
2059   tet_infoline("Testing RenderTask Render Once\n"
2060                "During RenderOnce, make ready resources unready before sending first finished signal\n"
2061                "PRE: Everything ready.\n"
2062                "POST: Finished signal sent only once");
2063
2064   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2065   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2066   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2067   drawTrace.Enable(true);
2068
2069   Actor rootActor = Actor::New();
2070   Stage::GetCurrent().Add( rootActor );
2071
2072   CameraActor offscreenCameraActor = CameraActor::New();
2073   Stage::GetCurrent().Add( offscreenCameraActor );
2074   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
2075   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2076   Integration::ResourceId imageRequestId = imageRequest->GetId();
2077   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2078   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2079   application.Render();
2080   application.GetPlatform().ClearReadyResources();
2081
2082   Stage::GetCurrent().Add(secondRootActor);
2083
2084   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2085   bool finished = false;
2086   RenderTaskFinished renderTaskFinished( finished );
2087   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2088   application.SendNotification();
2089
2090   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2091   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
2092   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false ) );
2093
2094   // CHANGE TO RENDER ONCE, RESOURCES BECOME NOT READY
2095   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2096
2097   // Doesn't work...
2098   ReloadImage(application, secondRootActor.GetImage());
2099   application.SendNotification(); //         Input,    Expected  Input,    Expected
2100
2101   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
2102   DALI_TEST_EQUALS( secondRootActor.GetImage().GetLoadingState(), Dali::ResourceLoading, TEST_LOCATION);
2103   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
2104
2105   // FINISH RESOURCE LOADING
2106   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2107   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, true, true ) );
2108   application.GetPlatform().ClearReadyResources();
2109   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
2110   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true  ) );
2111   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
2112   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
2113   END_TEST;
2114 }
2115 #endif
2116
2117 int UtcDaliRenderTaskOnceNoSync05(void)
2118 {
2119   TestApplication application;
2120
2121   tet_infoline("Testing RenderTask Render Once\n"
2122                "Render once, Second call to SetRefreshRate(ONCE) triggers only one more finished signal\n"
2123                "PRE: Everything ready\n"
2124                "POST: exactly 1 finished signal per call to SetRefreshRate(ONCE)");
2125
2126   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2127   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2128   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2129   drawTrace.Enable(true);
2130
2131   Actor rootActor = Actor::New();
2132   Stage::GetCurrent().Add( rootActor );
2133
2134   CameraActor offscreenCameraActor = CameraActor::New();
2135   Stage::GetCurrent().Add( offscreenCameraActor );
2136   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
2137   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2138   Integration::ResourceId imageRequestId = imageRequest->GetId();
2139   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2140   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2141   application.Render();
2142   application.GetPlatform().ClearReadyResources();
2143
2144   Stage::GetCurrent().Add(secondRootActor);
2145
2146   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2147   bool finished = false;
2148   RenderTaskFinished renderTaskFinished( finished );
2149   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2150   application.SendNotification();
2151
2152   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2153   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
2154   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false ) );
2155
2156   // CHANGE TO RENDER ONCE,
2157   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2158   application.SendNotification();
2159   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
2160   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false ) );
2161
2162   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2163   application.SendNotification();
2164   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
2165   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false ) );
2166   END_TEST;
2167 }
2168
2169 int UtcDaliRenderTaskOnceNoSync06(void)
2170 {
2171   TestApplication application;
2172
2173   tet_infoline("Testing RenderTask Render Once\n"
2174                "Render once, Call to SetRefreshRate(ONCE) in Finished signal callback triggers\n"
2175                "another render & another finished signal\n"
2176                "PRE: Everything ready\n"
2177                "POST: exactly 1 finished signal per call to SetRefreshRate(ONCE)");
2178
2179
2180   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2181   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2182   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2183   drawTrace.Enable(true);
2184
2185   Actor rootActor = Actor::New();
2186   Stage::GetCurrent().Add( rootActor );
2187
2188   CameraActor offscreenCameraActor = CameraActor::New();
2189   Stage::GetCurrent().Add( offscreenCameraActor );
2190   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
2191   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2192   Integration::ResourceId imageRequestId = imageRequest->GetId();
2193   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2194   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2195   application.Render();
2196   application.GetPlatform().ClearReadyResources();
2197
2198   Stage::GetCurrent().Add(secondRootActor);
2199
2200   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2201   bool finished = false;
2202
2203   ConnectionTracker connectionTracker;
2204   RenderTaskFinishedRenderAgain renderTaskFinishedRenderAgain( finished );
2205   newTask.FinishedSignal().Connect( &connectionTracker, renderTaskFinishedRenderAgain );
2206
2207   application.SendNotification();
2208
2209   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2210   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
2211   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false ) );
2212
2213   // CHANGE TO RENDER ONCE,
2214   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2215   application.SendNotification();
2216   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
2217   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false ) );
2218
2219   // Expect SetRefreshRate to have been called again
2220   // Prevent next finished signal calling refresh once again
2221   RenderTaskFinished renderTaskFinished( finished );
2222   connectionTracker.DisconnectAll();
2223   newTask.FinishedSignal().Connect( &connectionTracker, renderTaskFinished );
2224
2225   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
2226   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false ) );
2227   END_TEST;
2228 }
2229
2230
2231 int UtcDaliRenderTaskOnceNoSync07(void)
2232 {
2233   TestApplication application;
2234
2235   tet_infoline("Testing RenderTask Render Once\n"
2236                "SetRefreshRate(ONCE) again before first finished signal has been sent.\n"
2237                "PRE: resources ready\n"
2238                "POST: Only 1 finished signal sent.");
2239
2240   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2241   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2242   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2243   drawTrace.Enable(true);
2244
2245   Actor rootActor = Actor::New();
2246   Stage::GetCurrent().Add( rootActor );
2247
2248   CameraActor offscreenCameraActor = CameraActor::New();
2249   Stage::GetCurrent().Add( offscreenCameraActor );
2250   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
2251   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2252   Integration::ResourceId imageRequestId = imageRequest->GetId();
2253   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2254   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2255   application.Render();
2256   application.GetPlatform().ClearReadyResources();
2257
2258   Stage::GetCurrent().Add(secondRootActor);
2259
2260   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2261   bool finished = false;
2262   RenderTaskFinished renderTaskFinished( finished );
2263   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2264   application.SendNotification();
2265
2266   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2267   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
2268   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false ) );
2269
2270   // CHANGE TO RENDER ONCE,
2271   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2272   application.SendNotification();
2273   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
2274   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false ) );
2275
2276   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2277   application.SendNotification();
2278   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
2279   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false ) );
2280   END_TEST;
2281 }
2282
2283 int UtcDaliRenderTaskOnceNoSync08(void)
2284 {
2285   TestApplication application;
2286
2287   tet_infoline("Testing RenderTask Render Once\n"
2288                "SetRefreshRate(ONCE), resource load failed, completes render task.\n"
2289                "PRE: resources not ready\n"
2290                "POST: Only 1 finished signal sent.");
2291
2292   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2293   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2294   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2295   drawTrace.Enable(true);
2296
2297   Actor rootActor = Actor::New();
2298   Stage::GetCurrent().Add( rootActor );
2299
2300   CameraActor offscreenCameraActor = CameraActor::New();
2301   Stage::GetCurrent().Add( offscreenCameraActor );
2302   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
2303   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2304   Integration::ResourceId imageRequestId = imageRequest->GetId();
2305   Stage::GetCurrent().Add(secondRootActor);
2306
2307   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2308   bool finished = false;
2309   RenderTaskFinished renderTaskFinished( finished );
2310   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2311   application.SendNotification();
2312
2313   // START PROCESS/RENDER                    Input,     Expected  Input,    Expected
2314   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
2315   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
2316
2317   // CHANGE TO RENDER ONCE,
2318   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2319   application.SendNotification();
2320   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
2321   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
2322   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
2323
2324   FailImageLoad(application, imageRequestId); // Need to run Update again for this to complete
2325   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) ); // nothing to draw
2326   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, true,  false  ) );
2327
2328   END_TEST;
2329 }
2330
2331
2332
2333 int UtcDaliRenderTaskOnceChain01(void)
2334 {
2335   TestApplication application;
2336
2337   tet_infoline("Testing RenderTask Render Once Chained render tasks\n"
2338                "SetRefreshRate(ONCE), resource load completes, both render tasks render.\n"
2339                "PRE: resources not ready\n"
2340                "POST: 2 finished signals sent.");
2341
2342   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2343   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2344   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2345   drawTrace.Enable(true);
2346
2347   Actor defaultRootActor = Actor::New(); // Root for default RT
2348   Stage::GetCurrent().Add( defaultRootActor );
2349
2350   CameraActor offscreenCameraActor = CameraActor::New();
2351   Stage::GetCurrent().Add( offscreenCameraActor );
2352   ImageActor firstRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
2353   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2354   Integration::ResourceId imageRequestId = imageRequest->GetId();
2355   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2356   Stage::GetCurrent().Add(firstRootActor);
2357
2358   // first render task
2359   RenderTask firstTask = CreateRenderTask(application, offscreenCameraActor, defaultRootActor, firstRootActor, RenderTask::REFRESH_ONCE, false);
2360   bool firstFinished = false;
2361   RenderTaskFinished renderTask1Finished( firstFinished );
2362   firstTask.FinishedSignal().Connect( &application, renderTask1Finished );
2363
2364   // Second render task
2365   FrameBufferImage fbo = firstTask.GetTargetFrameBuffer();
2366   ImageActor secondRootActor = ImageActor::New( fbo );
2367   Stage::GetCurrent().Add(secondRootActor);
2368   RenderTask secondTask = CreateRenderTask(application, offscreenCameraActor, defaultRootActor, secondRootActor, RenderTask::REFRESH_ONCE, false);
2369   bool secondFinished = false;
2370   RenderTaskFinished renderTask2Finished( secondFinished );
2371   secondTask.FinishedSignal().Connect( &application, renderTask2Finished );
2372
2373   application.SendNotification();
2374
2375   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2376   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,  firstFinished, false, true ) );
2377   DALI_TEST_CHECK( secondFinished == false );
2378   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,  firstFinished, false, true ) );
2379   DALI_TEST_CHECK( secondFinished == false );
2380
2381   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2382   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,  firstFinished, false, true ) );
2383   DALI_TEST_CHECK( secondFinished == false );
2384   application.GetPlatform().ClearReadyResources();
2385
2386   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,  firstFinished, true,  false ) );
2387   DALI_TEST_CHECK( secondFinished == true );
2388
2389   END_TEST;
2390 }
2391
2392 int UtcDaliRenderTaskProperties(void)
2393 {
2394   TestApplication application;
2395
2396   RenderTask task = Stage::GetCurrent().GetRenderTaskList().CreateTask();
2397
2398   Property::IndexContainer indices;
2399   task.GetPropertyIndices( indices );
2400   DALI_TEST_CHECK( ! indices.empty() );
2401   DALI_TEST_EQUALS( indices.size(), task.GetPropertyCount(), TEST_LOCATION );
2402   END_TEST;
2403 }