Merge "DALi Version 1.0.28" into tizen
[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 // The functor to be used in the hit-test algorithm to check whether the actor is hittable.
315 bool IsActorHittableFunction(Actor actor, Dali::HitTestAlgorithm::TraverseType type)
316 {
317   bool hittable = false;
318
319   switch (type)
320   {
321     case Dali::HitTestAlgorithm::CHECK_ACTOR:
322     {
323       // Check whether the actor is visible and not fully transparent.
324       if( actor.IsVisible()
325        && actor.GetCurrentWorldColor().a > 0.01f) // not FULLY_TRANSPARENT
326       {
327
328           hittable = true;
329       }
330       break;
331     }
332     case Dali::HitTestAlgorithm::DESCEND_ACTOR_TREE:
333     {
334       if( actor.IsVisible() ) // Actor is visible, if not visible then none of its children are visible.
335       {
336         hittable = true;
337       }
338       break;
339     }
340     default:
341     {
342       break;
343     }
344   }
345
346   return hittable;
347 }
348
349 } // unnamed namespace
350
351
352 /****************************************************************************************************/
353 /****************************************************************************************************/
354 /********************************   TEST CASES BELOW   **********************************************/
355 /****************************************************************************************************/
356 /****************************************************************************************************/
357
358 int UtcDaliRenderTaskDownCast(void)
359 {
360   TestApplication application;
361
362   tet_infoline("Testing RenderTask::DownCast()");
363
364   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
365
366   BaseHandle base = taskList.GetTask( 0u );
367   DALI_TEST_CHECK( base );
368
369   RenderTask task = RenderTask::DownCast( base );
370   DALI_TEST_CHECK( task );
371
372   // Try calling a method
373   DALI_TEST_CHECK( task.GetSourceActor() );
374   END_TEST;
375 }
376
377 int UtcDaliRenderTaskSetSourceActor(void)
378 {
379   TestApplication application;
380
381   tet_infoline("Testing RenderTask::SetSourceActor()");
382
383   Stage stage = Stage::GetCurrent();
384
385   const std::vector<GLuint>& boundTextures = application.GetGlAbstraction().GetBoundTextures( GL_TEXTURE0 );
386
387   RenderTaskList taskList = stage.GetRenderTaskList();
388
389   RenderTask task = taskList.GetTask( 0u );
390
391   Actor actor = task.GetSourceActor();
392   DALI_TEST_CHECK( actor );
393
394   std::vector<GLuint> ids;
395   ids.push_back( 7 );
396   application.GetGlAbstraction().SetNextTextureIds( ids );
397
398   BitmapImage img = BitmapImage::New( 1,1 );
399   ImageActor newActor = ImageActor::New( img );
400   newActor.SetSize(1,1);
401   stage.Add( newActor );
402
403   Actor nonRenderableActor = Actor::New();
404   stage.Add( nonRenderableActor );
405
406   // Stop the newActor from being rendered by changing the source actor
407   DALI_TEST_CHECK( nonRenderableActor );
408   task.SetSourceActor( nonRenderableActor );
409   DALI_TEST_CHECK( task.GetSourceActor() != actor );
410   DALI_TEST_CHECK( task.GetSourceActor() == nonRenderableActor );
411
412   // Update & Render nothing!
413   application.GetGlAbstraction().ClearBoundTextures();
414   application.SendNotification();
415   application.Render();
416
417   // Check that nothing was rendered
418   DALI_TEST_EQUALS( boundTextures.size(), 0u, TEST_LOCATION );
419
420   // Set newActor as the new source Actor
421   task.SetSourceActor( newActor );
422   DALI_TEST_CHECK( task.GetSourceActor() != actor );
423   DALI_TEST_CHECK( task.GetSourceActor() == newActor );
424
425   // Update & Render the newActor
426   application.GetGlAbstraction().ClearBoundTextures();
427   application.SendNotification();
428   application.Render();
429
430   // Check that the newActor was rendered
431   DALI_TEST_EQUALS( boundTextures.size(), 1u, TEST_LOCATION );
432   if ( boundTextures.size() )
433   {
434     DALI_TEST_EQUALS( boundTextures[0], 7u, TEST_LOCATION );
435   }
436   END_TEST;
437 }
438
439 int UtcDaliRenderTaskSetSourceActorOffStage(void)
440 {
441   TestApplication application;
442
443   tet_infoline("Testing RenderTask::SetSourceActor (on/off stage testing)");
444
445   Stage stage = Stage::GetCurrent();
446
447   const std::vector<GLuint>& boundTextures = application.GetGlAbstraction().GetBoundTextures( GL_TEXTURE0 );
448
449   RenderTaskList taskList = stage.GetRenderTaskList();
450
451   RenderTask task = taskList.GetTask( 0u );
452
453   Actor actor = task.GetSourceActor();
454   DALI_TEST_CHECK( actor );
455
456   std::vector<GLuint> ids;
457   GLuint expectedTextureId( 3 );
458   ids.push_back( expectedTextureId );
459   application.GetGlAbstraction().SetNextTextureIds( ids );
460
461   BitmapImage img = BitmapImage::New( 1,1 );
462   ImageActor newActor = ImageActor::New( img );
463   newActor.SetSize(1,1);
464   task.SetSourceActor( newActor );
465   // Don't add newActor to stage yet
466
467   // Update & Render with the actor initially off-stage
468   application.GetGlAbstraction().ClearBoundTextures();
469   application.SendNotification();
470   application.Render();
471
472   // Check that nothing was rendered
473   DALI_TEST_EQUALS( boundTextures.size(), 0u, TEST_LOCATION );
474
475   // Now add to stage
476   stage.Add( newActor );
477
478   // Update & Render with the actor on-stage
479   application.GetGlAbstraction().ClearBoundTextures();
480   application.SendNotification();
481   application.Render();
482
483   // Check that the newActor was rendered
484   DALI_TEST_EQUALS( boundTextures.size(), 1u, TEST_LOCATION );
485   if ( boundTextures.size() )
486   {
487     DALI_TEST_EQUALS( boundTextures[0], expectedTextureId, TEST_LOCATION );
488   }
489
490   // Now remove from stage
491   stage.Remove( newActor );
492
493   // Update & Render with the actor off-stage
494   application.GetGlAbstraction().ClearBoundTextures();
495   application.SendNotification();
496   application.Render();
497   END_TEST;
498 }
499
500 int UtcDaliRenderTaskSetSourceActorEmpty(void)
501 {
502   TestApplication application;
503
504   tet_infoline("Testing RenderTask::SetSourceActor (empty handle case)");
505
506   Stage stage = Stage::GetCurrent();
507
508   const std::vector<GLuint>& boundTextures = application.GetGlAbstraction().GetBoundTextures( GL_TEXTURE0 );
509
510   RenderTaskList taskList = stage.GetRenderTaskList();
511
512   RenderTask task = taskList.GetTask( 0u );
513
514   Actor actor = task.GetSourceActor();
515   DALI_TEST_CHECK( actor );
516
517   std::vector<GLuint> ids;
518   GLuint expectedTextureId( 5 );
519   ids.push_back( expectedTextureId );
520   application.GetGlAbstraction().SetNextTextureIds( ids );
521
522   BitmapImage img = BitmapImage::New( 1,1 );
523   ImageActor newActor = ImageActor::New( img );
524   newActor.SetSize(1,1);
525   stage.Add( newActor );
526
527   Actor nonRenderableActor = Actor::New();
528   stage.Add( nonRenderableActor );
529
530   // Set with empty handle
531   task.SetSourceActor( Actor() );
532   DALI_TEST_CHECK( ! task.GetSourceActor() );
533
534   // Update & Render nothing!
535   application.GetGlAbstraction().ClearBoundTextures();
536   application.SendNotification();
537   application.Render();
538
539   // Check that nothing was rendered
540   DALI_TEST_EQUALS( boundTextures.size(), 0u, TEST_LOCATION );
541
542   // Set with non-empty handle
543   task.SetSourceActor( newActor );
544   DALI_TEST_CHECK( task.GetSourceActor() == newActor );
545
546   // Update & Render the newActor
547   application.GetGlAbstraction().ClearBoundTextures();
548   application.SendNotification();
549   application.Render();
550
551   // Check that the newActor was rendered
552   DALI_TEST_EQUALS( boundTextures.size(), 1u, TEST_LOCATION );
553   if ( boundTextures.size() )
554   {
555     DALI_TEST_EQUALS( boundTextures[0], expectedTextureId, TEST_LOCATION );
556   }
557   END_TEST;
558 }
559
560 int UtcDaliRenderTaskGetSourceActor(void)
561 {
562   TestApplication application;
563
564   tet_infoline("Testing RenderTask::GetSourceActor()");
565
566   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
567
568   RenderTask task = taskList.GetTask( 0u );
569
570   Actor actor = task.GetSourceActor();
571   DALI_TEST_CHECK( actor );
572
573   // By default the entire scene should be rendered
574   Actor root = Stage::GetCurrent().GetLayer( 0 );
575   DALI_TEST_CHECK( root == actor );
576   END_TEST;
577 }
578
579 int UtcDaliRenderTaskSetExclusive(void)
580 {
581   TestApplication application;
582
583   tet_infoline("Testing RenderTask::SetExclusive()");
584
585   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
586
587   // Manipulate the GenTextures behaviour, to identify different ImageActors
588
589   std::vector<GLuint> ids;
590   ids.push_back( 8 ); // 8 = actor1
591   ids.push_back( 9 ); // 9 = actor2
592   ids.push_back( 10 ); // 10 = actor3
593   application.GetGlAbstraction().SetNextTextureIds( ids );
594
595   BitmapImage img1 = BitmapImage::New( 1,1 );
596   ImageActor actor1 = ImageActor::New( img1 );
597   actor1.SetSize(1,1);
598   Stage::GetCurrent().Add( actor1 );
599
600   // Update & Render actor1
601   application.SendNotification();
602   application.Render();
603
604   // Check that the actor1 was rendered
605   const std::vector<GLuint>& boundTextures = application.GetGlAbstraction().GetBoundTextures( GL_TEXTURE0 );
606   DALI_TEST_EQUALS( boundTextures.size(), 1u, TEST_LOCATION );
607
608   if ( boundTextures.size() )
609   {
610     DALI_TEST_EQUALS( boundTextures[0], 8u/*unique to actor1*/, TEST_LOCATION );
611   }
612
613   BitmapImage img2 = BitmapImage::New( 1,1 );
614   ImageActor actor2 = ImageActor::New( img2 );
615   actor2.SetSize(1,1);
616
617   // Force actor2 to be rendered before actor1
618   Layer layer = Layer::New();
619   Stage::GetCurrent().Add( layer );
620   layer.Add( actor2 );
621   layer.LowerToBottom();
622
623   // Update & Render
624   application.GetGlAbstraction().ClearBoundTextures();
625   application.SendNotification();
626   application.Render();
627
628   // Check that the actors were rendered
629   DALI_TEST_EQUALS( boundTextures.size(), 2u, TEST_LOCATION );
630
631   if ( boundTextures.size() )
632   {
633     DALI_TEST_EQUALS( boundTextures[0], 9u/*unique to actor2*/, TEST_LOCATION );
634     DALI_TEST_EQUALS( boundTextures[1], 8u/*unique to actor1*/, TEST_LOCATION );
635   }
636
637   BitmapImage img3 = BitmapImage::New( 1,1 );
638   ImageActor actor3 = ImageActor::New( img3 );
639   actor3.SetSize(1,1);
640
641   // Force actor3 to be rendered before actor2
642   layer = Layer::New();
643   Stage::GetCurrent().Add( layer );
644   layer.Add( actor3 );
645   layer.LowerToBottom();
646
647   // Update & Render all actors
648   application.GetGlAbstraction().ClearBoundTextures();
649   application.SendNotification();
650   application.Render();
651
652   // Check that the actors were rendered
653   DALI_TEST_EQUALS( boundTextures.size(), 3u, TEST_LOCATION );
654
655   if ( boundTextures.size() )
656   {
657     DALI_TEST_EQUALS( boundTextures[0], 10u/*unique to actor3*/, TEST_LOCATION );
658     DALI_TEST_EQUALS( boundTextures[1], 9u/*unique to actor2*/, TEST_LOCATION );
659     DALI_TEST_EQUALS( boundTextures[2], 8u/*unique to actor1*/, TEST_LOCATION );
660   }
661
662   // Both actors are now connected to the root node
663   // Setup 2 render-tasks - the first will render from the root-node, and the second from actor2
664
665   // Not exclusive is the default
666   RenderTask task1 = taskList.GetTask( 0u );
667   DALI_TEST_CHECK( false == task1.IsExclusive() );
668
669   RenderTask task2 = taskList.CreateTask();
670   DALI_TEST_CHECK( false == task2.IsExclusive() );
671   task2.SetSourceActor( actor2 );
672
673   // Task1 should render all actors, and task 2 should render only actor2
674
675   application.GetGlAbstraction().ClearBoundTextures();
676   application.SendNotification();
677   application.Render();
678
679   DALI_TEST_EQUALS( boundTextures.size(), 4u, TEST_LOCATION );
680
681   if ( boundTextures.size() == 4 )
682   {
683     // Test that task 1 renders actor3, then actor2 & then actor1
684     DALI_TEST_CHECK( boundTextures[0] == 10u );
685     DALI_TEST_CHECK( boundTextures[1] == 9u );
686     DALI_TEST_CHECK( boundTextures[2] == 8u );
687
688     // Test that task 2 renders actor2
689     DALI_TEST_EQUALS( boundTextures[3], 9u, TEST_LOCATION );
690   }
691
692   // Make actor2 exclusive to task2
693
694   task2.SetExclusive( true );
695   DALI_TEST_CHECK( true == task2.IsExclusive() );
696
697   // Task1 should render only actor1, and task 2 should render only actor2
698
699   application.GetGlAbstraction().ClearBoundTextures();
700   application.SendNotification();
701   application.Render();
702
703   DALI_TEST_EQUALS( boundTextures.size(), 3u, TEST_LOCATION );
704   if ( boundTextures.size() == 3 )
705   {
706     // Test that task 1 renders actor3 & actor1
707     DALI_TEST_CHECK( boundTextures[0] == 10u );
708     DALI_TEST_CHECK( boundTextures[1] == 8u );
709
710     // Test that task 2 renders actor2
711     DALI_TEST_CHECK( boundTextures[2] == 9u );
712   }
713   END_TEST;
714 }
715
716 int UtcDaliRenderTaskIsExclusive(void)
717 {
718   TestApplication application;
719
720   tet_infoline("Testing RenderTask::IsExclusive()");
721
722   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
723
724   // Not exclusive is the default
725   RenderTask task = taskList.GetTask( 0u );
726   DALI_TEST_CHECK( false == task.IsExclusive() );
727
728   RenderTask newTask = taskList.CreateTask();
729   DALI_TEST_CHECK( false == newTask.IsExclusive() );
730   END_TEST;
731 }
732
733 int UtcDaliRenderTaskSetInputEnabled(void)
734 {
735   TestApplication application;
736
737   tet_infoline("Testing RenderTask::SetInputEnabled()");
738
739   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
740
741   // Input is enabled by default
742   RenderTask task = taskList.GetTask( 0u );
743   DALI_TEST_CHECK( true == task.GetInputEnabled() );
744
745   task.SetInputEnabled( false );
746   DALI_TEST_CHECK( false == task.GetInputEnabled() );
747
748   task.SetInputEnabled( true );
749   DALI_TEST_CHECK( true == task.GetInputEnabled() );
750   END_TEST;
751 }
752
753 int UtcDaliRenderTaskGetInputEnabled(void)
754 {
755   TestApplication application;
756
757   tet_infoline("Testing RenderTask::GetInputEnabled()");
758
759   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
760
761   // Input is enabled by default
762   RenderTask task = taskList.GetTask( 0u );
763   DALI_TEST_CHECK( true == task.GetInputEnabled() );
764
765   RenderTask newTask = taskList.CreateTask();
766   DALI_TEST_CHECK( true == newTask.GetInputEnabled() );
767   END_TEST;
768 }
769
770 int UtcDaliRenderTaskSetCameraActor(void)
771 {
772   TestApplication application;
773
774   tet_infoline("Testing RenderTask::SetCameraActor()");
775
776   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
777
778   RenderTask task = taskList.GetTask( 0u );
779
780   Actor actor = task.GetCameraActor();
781   DALI_TEST_CHECK( actor );
782
783   CameraActor newActor = CameraActor::New();
784   DALI_TEST_CHECK( newActor );
785
786   task.SetCameraActor( newActor );
787   DALI_TEST_CHECK( task.GetCameraActor() != actor );
788   DALI_TEST_CHECK( task.GetCameraActor() == newActor );
789   END_TEST;
790 }
791
792 int UtcDaliRenderTaskGetCameraActor(void)
793 {
794   TestApplication application;
795
796   tet_infoline("Testing RenderTask::GetCameraActor()");
797
798   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
799
800   RenderTask task = taskList.GetTask( 0u );
801
802   Actor actor = task.GetCameraActor();
803   DALI_TEST_CHECK( actor );
804
805   RenderTask newTask = taskList.CreateTask();
806   DALI_TEST_CHECK( actor == newTask.GetCameraActor() );
807   END_TEST;
808 }
809
810 int UtcDaliRenderTaskSetTargetFrameBuffer(void)
811 {
812   TestApplication application;
813
814   tet_infoline("Testing RenderTask::SetTargetFrameBuffer()");
815
816   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
817
818   RenderTask task = taskList.GetTask( 0u );
819
820   // By default render-tasks do not render off-screen
821   FrameBufferImage image = task.GetTargetFrameBuffer();
822   DALI_TEST_CHECK( !image );
823
824   FrameBufferImage newImage = FrameBufferImage::New();
825
826   task.SetTargetFrameBuffer( newImage );
827   DALI_TEST_CHECK( task.GetTargetFrameBuffer() == newImage );
828   END_TEST;
829 }
830
831 int UtcDaliRenderTaskGetTargetFrameBuffer(void)
832 {
833   TestApplication application;
834
835   tet_infoline("Testing RenderTask::GetTargetFrameBuffer()");
836
837   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
838
839   RenderTask task = taskList.GetTask( 0u );
840
841   // By default render-tasks do not render off-screen
842   FrameBufferImage image = task.GetTargetFrameBuffer();
843   DALI_TEST_CHECK( !image );
844
845   RenderTask newTask = taskList.CreateTask();
846   DALI_TEST_CHECK( !newTask.GetTargetFrameBuffer() );
847   END_TEST;
848 }
849
850 int UtcDaliRenderTaskSetScreenToFrameBufferFunction(void)
851 {
852   TestApplication application;
853
854   tet_infoline("Testing RenderTask::SetScreenToFrameBufferFunction()");
855
856   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
857
858   RenderTask task = taskList.GetTask( 0u );
859
860   task.SetScreenToFrameBufferFunction( TestScreenToFrameBufferFunction );
861
862   Vector2 coordinates( 5, 10 );
863   Vector2 convertedCoordinates( 6, 12 ); // + Vector(1, 2)
864
865   RenderTask::ScreenToFrameBufferFunction func = task.GetScreenToFrameBufferFunction();
866   DALI_TEST_CHECK( func( coordinates ) );
867   DALI_TEST_CHECK( coordinates == convertedCoordinates );
868
869   task.SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );
870   func = task.GetScreenToFrameBufferFunction();
871   DALI_TEST_CHECK( func( coordinates ) );
872
873   task.SetScreenToFrameBufferFunction( RenderTask::DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION );
874   func = task.GetScreenToFrameBufferFunction();
875   DALI_TEST_CHECK( ! func( coordinates ) );
876   END_TEST;
877 }
878
879 int UtcDaliRenderTaskGetScreenToFrameBufferFunction(void)
880 {
881   TestApplication application;
882
883   tet_infoline("Testing RenderTask::GetScreenToFrameBufferFunction()");
884
885   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
886
887   RenderTask task = taskList.GetTask( 0u );
888
889   Vector2 originalCoordinates( 5, 10 );
890   Vector2 coordinates( 5, 10 );
891
892   RenderTask::ScreenToFrameBufferFunction func = task.GetScreenToFrameBufferFunction();
893   DALI_TEST_CHECK( !func( coordinates ) ); // conversion should fail by default
894   DALI_TEST_CHECK( coordinates == originalCoordinates ); // coordinates should not be modified
895   END_TEST;
896 }
897
898
899 int UtcDaliRenderTaskGetScreenToFrameBufferMappingActor(void)
900 {
901   TestApplication application;
902   tet_infoline("Testing RenderTask::GetScreenToFrameBufferMappingActor ");
903
904   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
905   RenderTask renderTask = taskList.CreateTask();
906   Actor mappingActor = Actor::New();
907   renderTask.SetScreenToFrameBufferMappingActor(mappingActor);
908
909   DALI_TEST_CHECK( mappingActor == renderTask.GetScreenToFrameBufferMappingActor() );
910   END_TEST;
911 }
912
913 int UtcDaliRenderTaskSetViewport(void)
914 {
915   TestApplication application;
916
917   tet_infoline("Testing RenderTask::SetViewport()");
918
919   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
920
921   RenderTask task = taskList.GetTask( 0u );
922
923   Viewport viewport = task.GetViewport();
924
925   // By default the viewport should match the stage width/height
926
927   Vector2 stageSize = Stage::GetCurrent().GetSize();
928   Viewport expectedViewport( 0, 0, stageSize.width, stageSize.height );
929   DALI_TEST_CHECK( viewport == expectedViewport );
930
931   Viewport newViewport( 0, 0, stageSize.width * 0.5f, stageSize.height * 0.5f );
932   task.SetViewport( newViewport );
933
934   // Update (viewport is a property)
935   application.SendNotification();
936   application.Render();
937
938   DALI_TEST_CHECK( task.GetViewport() == newViewport );
939   END_TEST;
940 }
941
942 int UtcDaliRenderTaskGetViewport(void)
943 {
944   TestApplication application;
945
946   tet_infoline("Testing RenderTask::GetViewport()");
947
948   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
949
950   RenderTask task = taskList.GetTask( 0u );
951
952   Viewport viewport = task.GetViewport();
953
954   // By default the viewport should match the stage width/height
955
956   Vector2 stageSize = Stage::GetCurrent().GetSize();
957   Viewport expectedViewport( 0, 0, stageSize.width, stageSize.height );
958   DALI_TEST_CHECK( viewport == expectedViewport );
959
960   RenderTask newTask = taskList.CreateTask();
961   DALI_TEST_CHECK( newTask.GetViewport() == expectedViewport );
962   END_TEST;
963 }
964
965 int UtcDaliRenderTaskSetViewportPosition(void)
966 {
967   TestApplication application;
968
969   tet_infoline("Testing RenderTask::SetViewportPosition()");
970
971   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
972
973   RenderTask task = taskList.GetTask( 0u );
974
975   Viewport viewport = task.GetViewport();
976
977   // By default the viewport should match the stage width/height
978
979   Vector2 stageSize = Stage::GetCurrent().GetSize();
980   Viewport expectedViewport( 0, 0, stageSize.width, stageSize.height );
981   DALI_TEST_CHECK( viewport == expectedViewport );
982
983   // 'Setter' test
984   Vector2 newPosition(25.0f, 50.0f);
985   task.SetViewportPosition( newPosition );
986
987   // Update (viewport is a property)
988   application.SendNotification();
989   application.Render();
990
991   DALI_TEST_EQUALS( task.GetCurrentViewportPosition(), newPosition, Math::MACHINE_EPSILON_1, TEST_LOCATION );
992
993   // Set by Property test
994   Vector2 newPosition2(32.0f, 32.0f);
995   task.SetProperty( RenderTask::VIEWPORT_POSITION, newPosition2 );
996
997   // Update
998   application.SendNotification();
999   application.Render();
1000
1001   DALI_TEST_EQUALS( task.GetCurrentViewportPosition(), newPosition2, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1002
1003   Vector2 newPosition3(64.0f, 0.0f);
1004   Animation animation = Animation::New(1.0f);
1005   animation.AnimateTo( Property( task, RenderTask::VIEWPORT_POSITION ), newPosition3, AlphaFunctions::Linear );
1006   animation.Play();
1007
1008   // Perform 1000ms worth of updates at which point animation should have completed.
1009   Wait(application, 1000);
1010   DALI_TEST_EQUALS( task.GetCurrentViewportPosition(), newPosition3, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1011   END_TEST;
1012 }
1013
1014 int UtcDaliRenderTaskSetViewportSize(void)
1015 {
1016   TestApplication application;
1017
1018   tet_infoline("Testing RenderTask::SetViewportSize()");
1019
1020   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1021
1022   RenderTask task = taskList.GetTask( 0u );
1023
1024   Viewport viewport = task.GetViewport();
1025
1026   // By default the viewport should match the stage width/height
1027
1028   Vector2 stageSize = Stage::GetCurrent().GetSize();
1029   Viewport expectedViewport( 0, 0, stageSize.width, stageSize.height );
1030   DALI_TEST_CHECK( viewport == expectedViewport );
1031
1032   Vector2 newSize(128.0f, 64.0f);
1033   task.SetViewportSize( newSize );
1034
1035   // Update (viewport is a property)
1036   application.SendNotification();
1037   application.Render();
1038
1039   DALI_TEST_EQUALS( task.GetCurrentViewportSize(), newSize, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1040
1041   // Set by Property test
1042   Vector2 newSize2(50.0f, 50.0f);
1043   task.SetProperty( RenderTask::VIEWPORT_SIZE, newSize2 );
1044
1045   // Update
1046   application.SendNotification();
1047   application.Render();
1048
1049   DALI_TEST_EQUALS( task.GetCurrentViewportSize(), newSize2, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1050
1051   Vector2 newSize3(10.0f, 10.0f);
1052   Animation animation = Animation::New(1.0f);
1053   animation.AnimateTo( Property( task, RenderTask::VIEWPORT_SIZE ), newSize3, AlphaFunctions::Linear );
1054   animation.Play();
1055
1056   // Perform 1000ms worth of updates at which point animation should have completed.
1057   Wait(application, 1000);
1058   DALI_TEST_EQUALS( task.GetCurrentViewportSize(), newSize3, Math::MACHINE_EPSILON_1, TEST_LOCATION );
1059
1060   END_TEST;
1061 }
1062
1063 int UtcDaliRenderTaskSetClearColor(void)
1064 {
1065   TestApplication application;
1066
1067   tet_infoline("Testing RenderTask::SetClearColor()");
1068
1069   Vector4 testColor( 1.0f, 2.0f, 3.0f, 4.0f );
1070   Vector4 testColor2( 5.0f, 6.0f, 7.0f, 8.0f );
1071
1072   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1073
1074   RenderTask task = taskList.GetTask( 0u );
1075   DALI_TEST_CHECK( task.GetClearColor() != testColor );
1076
1077   task.SetClearColor( testColor );
1078
1079   // Wait a frame.
1080   Wait(application);
1081
1082   DALI_TEST_EQUALS( task.GetClearColor(), testColor, TEST_LOCATION );
1083
1084   task.SetProperty( RenderTask::CLEAR_COLOR, testColor2 );
1085
1086   // Wait a frame.
1087   Wait(application);
1088
1089   DALI_TEST_EQUALS( task.GetClearColor(), testColor2, TEST_LOCATION );
1090   END_TEST;
1091 }
1092
1093 int UtcDaliRenderTaskGetClearColor(void)
1094 {
1095   TestApplication application;
1096
1097   tet_infoline("Testing RenderTask::GetClearColor()");
1098
1099   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1100   RenderTask task = taskList.GetTask( 0u );
1101   DALI_TEST_EQUALS( task.GetClearColor(), RenderTask::DEFAULT_CLEAR_COLOR, TEST_LOCATION );
1102   END_TEST;
1103 }
1104
1105 int UtcDaliRenderTaskSetClearEnabled(void)
1106 {
1107   TestApplication application;
1108
1109   tet_infoline("Testing RenderTask::SetClearEnabled()");
1110
1111   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1112
1113   RenderTask task = taskList.GetTask( 0u );
1114   DALI_TEST_CHECK( !task.GetClearEnabled() ); // defaults to false
1115
1116   task.SetClearEnabled( true );
1117   DALI_TEST_EQUALS( task.GetClearEnabled(), true, TEST_LOCATION );
1118
1119   task.SetClearEnabled( false );
1120   DALI_TEST_EQUALS( task.GetClearEnabled(), false, TEST_LOCATION );
1121   END_TEST;
1122 }
1123
1124 int UtcDaliRenderTaskGetClearEnabled(void)
1125 {
1126   TestApplication application;
1127
1128   tet_infoline("Testing RenderTask::GetClearEnabled()");
1129
1130   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1131
1132   RenderTask task = taskList.GetTask( 0u );
1133   DALI_TEST_CHECK( !task.GetClearEnabled() ); // defaults to false
1134   END_TEST;
1135 }
1136
1137 int UtcDaliRenderTaskSetRefreshRate(void)
1138 {
1139   TestApplication application;
1140
1141   tet_infoline("Testing RenderTask::SetRefreshRate()");
1142
1143   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1144
1145   // By default tasks will be processed every frame
1146   RenderTask task = taskList.GetTask( 0u );
1147   DALI_TEST_CHECK( RenderTask::REFRESH_ALWAYS == task.GetRefreshRate() );
1148
1149   task.SetRefreshRate( 2u ); // every-other frame
1150   DALI_TEST_CHECK( 2u == task.GetRefreshRate() );
1151
1152   task.SetRefreshRate( RenderTask::REFRESH_ALWAYS );
1153   DALI_TEST_CHECK( RenderTask::REFRESH_ALWAYS == task.GetRefreshRate() );
1154   END_TEST;
1155 }
1156
1157 int UtcDaliRenderTaskGetRefreshRate(void)
1158 {
1159   TestApplication application;
1160
1161   tet_infoline("Testing RenderTask::GetRefreshRate()");
1162
1163   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1164
1165   // By default tasks will be processed every frame
1166   RenderTask task = taskList.GetTask( 0u );
1167   DALI_TEST_CHECK( RenderTask::REFRESH_ALWAYS == task.GetRefreshRate() );
1168
1169   RenderTask newTask = taskList.CreateTask();
1170   DALI_TEST_CHECK( RenderTask::REFRESH_ALWAYS == newTask.GetRefreshRate() );
1171   END_TEST;
1172 }
1173
1174 int UtcDaliRenderTaskSignalFinished(void)
1175 {
1176   TestApplication application;
1177
1178   tet_infoline("Testing RenderTask::SignalFinished()");
1179
1180   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1181   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
1182
1183   CameraActor offscreenCameraActor = CameraActor::New();
1184
1185   Stage::GetCurrent().Add( offscreenCameraActor );
1186
1187   BitmapImage image = BitmapImage::New( 10, 10 );
1188   ImageActor rootActor = ImageActor::New( image );
1189   rootActor.SetSize( 10, 10 );
1190   Stage::GetCurrent().Add( rootActor );
1191
1192   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
1193   NativeImagePtr testNativeImagePtr = new TestNativeImage(10, 10);
1194   FrameBufferImage frameBufferImage = FrameBufferImage::New( *testNativeImagePtr.Get() );
1195
1196   // Flush all outstanding messages
1197   application.SendNotification();
1198   application.Render();
1199
1200   RenderTask newTask = taskList.CreateTask();
1201   newTask.SetCameraActor( offscreenCameraActor );
1202   newTask.SetSourceActor( rootActor );
1203   newTask.SetInputEnabled( false );
1204   newTask.SetClearColor( Vector4( 0.f, 0.f, 0.f, 0.f ) );
1205   newTask.SetClearEnabled( true );
1206   newTask.SetExclusive( true );
1207   newTask.SetRefreshRate( RenderTask::REFRESH_ONCE );
1208   newTask.SetTargetFrameBuffer( frameBufferImage );
1209
1210   // Framebuffer doesn't actually get created until Connected, i.e. by previous line
1211
1212   bool finished = false;
1213   RenderTaskFinished renderTaskFinished( finished );
1214   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1215
1216   // Flush the queue and render.
1217   application.SendNotification();
1218
1219   // 1 render to process render task, then wait for sync before finished msg is sent
1220   // from update to the event thread.
1221
1222   application.Render();
1223   application.SendNotification();
1224   DALI_TEST_CHECK( !finished );
1225
1226   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
1227   DALI_TEST_CHECK( lastSyncObj != NULL );
1228
1229   application.Render();
1230   DALI_TEST_EQUALS( (application.GetUpdateStatus() & Integration::KeepUpdating::RENDER_TASK_SYNC), Integration::KeepUpdating::RENDER_TASK_SYNC, TEST_LOCATION );
1231   application.SendNotification();
1232   DALI_TEST_CHECK( !finished );
1233
1234   application.Render();
1235   DALI_TEST_EQUALS( (application.GetUpdateStatus() & Integration::KeepUpdating::RENDER_TASK_SYNC), Integration::KeepUpdating::RENDER_TASK_SYNC, TEST_LOCATION );
1236   application.SendNotification();
1237   DALI_TEST_CHECK( ! finished );
1238
1239   sync.SetObjectSynced( lastSyncObj, true );
1240
1241   application.Render();
1242   application.SendNotification();
1243   DALI_TEST_CHECK( !finished );
1244
1245   application.Render();
1246   application.SendNotification();
1247   DALI_TEST_CHECK( finished );
1248   finished = false;
1249
1250   application.Render(); // Double check no more finished signal
1251   application.SendNotification();
1252   DALI_TEST_CHECK( ! finished );
1253   END_TEST;
1254 }
1255
1256
1257 int UtcDaliRenderTaskContinuous01(void)
1258 {
1259   TestApplication application;
1260
1261   tet_infoline("Testing RenderTask Render Continuous using loading image\nPRE: render task not ready (source actor not staged)\nPOST:continuous renders, no Finished signal");
1262
1263   // SETUP AN OFFSCREEN RENDER TASK
1264   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1265   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1266   drawTrace.Enable(true);
1267
1268   Actor rootActor = Actor::New();
1269   Stage::GetCurrent().Add( rootActor );
1270
1271   CameraActor offscreenCameraActor = CameraActor::New();
1272   Stage::GetCurrent().Add( offscreenCameraActor );
1273
1274   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1275   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1276   Integration::ResourceId imageRequestId = imageRequest->GetId();
1277   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1278
1279   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1280   bool finished = false;
1281   RenderTaskFinished renderTaskFinished( finished );
1282   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1283   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1284   application.SendNotification();
1285
1286   // START PROCESS/RENDER                     Input,    Expected  Input, Expected, KeepUpdating
1287   DALI_TEST_CHECK( UpdateRender(application,  drawTrace, false,   finished, false, true ) );
1288   application.GetPlatform().ClearReadyResources();
1289
1290   DALI_TEST_CHECK( UpdateRender(application,  drawTrace, false,   finished, false, false ) );
1291
1292   // ADD SOURCE ACTOR TO STAGE - expect continuous renders to start, no finished signal
1293   Stage::GetCurrent().Add(secondRootActor);
1294   application.SendNotification();
1295
1296   // CONTINUE PROCESS/RENDER                  Input,    Expected  Input,    Expected
1297   DALI_TEST_CHECK( UpdateRender(application,  drawTrace, true,    finished, false, true ) );
1298   DALI_TEST_CHECK( UpdateRender(application,  drawTrace, true,    finished, false, false ) );
1299   END_TEST;
1300 }
1301
1302
1303 int UtcDaliRenderTaskContinuous02(void)
1304 {
1305   TestApplication application;
1306
1307   tet_infoline("Testing RenderTask Render Continuous using loading image\nPRE: render task not ready (source actor not visible)\nPOST:continuous renders, no Finished signal");
1308
1309   // SETUP AN OFFSCREEN RENDER TASK
1310   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1311   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1312   drawTrace.Enable(true);
1313
1314   Actor rootActor = Actor::New();
1315   Stage::GetCurrent().Add( rootActor );
1316
1317   CameraActor offscreenCameraActor = CameraActor::New();
1318   Stage::GetCurrent().Add( offscreenCameraActor );
1319
1320   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1321   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1322   Integration::ResourceId imageRequestId = imageRequest->GetId();
1323   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1324   Stage::GetCurrent().Add(secondRootActor);
1325   secondRootActor.SetVisible(false);
1326
1327   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1328   bool finished = false;
1329   RenderTaskFinished renderTaskFinished( finished );
1330   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1331   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1332   application.SendNotification();
1333
1334   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1335   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1336   application.GetPlatform().ClearReadyResources();
1337   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, false ) );
1338
1339   // MAKE SOURCE ACTOR VISIBLE - expect continuous renders to start, no finished signal
1340   secondRootActor.SetVisible(true);
1341   application.SendNotification();
1342
1343   // CONTINUE PROCESS/RENDER                 Input,    Expected  Input,    Expected
1344   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1345   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false ) );
1346   END_TEST;
1347 }
1348
1349 int UtcDaliRenderTaskContinuous03(void)
1350 {
1351   TestApplication application;
1352
1353   tet_infoline("Testing RenderTask Render Continuous using loading image\nPRE: render task not ready (camera actor not staged)\nPOST:continuous renders, no Finished signal");
1354
1355   // SETUP AN OFFSCREEN RENDER TASK
1356   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1357   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1358   drawTrace.Enable(true);
1359
1360   Actor rootActor = Actor::New();
1361   Stage::GetCurrent().Add( rootActor );
1362
1363   CameraActor offscreenCameraActor = CameraActor::New();
1364   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1365   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1366   Integration::ResourceId imageRequestId = imageRequest->GetId();
1367   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1368   Stage::GetCurrent().Add(secondRootActor);
1369
1370   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1371   bool finished = false;
1372   RenderTaskFinished renderTaskFinished( finished );
1373   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1374   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1375   application.SendNotification();
1376
1377   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1378   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1379   application.GetPlatform().ClearReadyResources();
1380   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, false ) );
1381
1382   // ADD CAMERA ACTOR TO STAGE - expect continuous renders to start, no finished signal
1383   Stage::GetCurrent().Add( offscreenCameraActor );
1384   application.SendNotification();
1385
1386   // CONTINUE PROCESS/RENDER                 Input,    Expected  Input,    Expected
1387   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1388   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false ) );
1389   END_TEST;
1390 }
1391
1392
1393 int UtcDaliRenderTaskContinuous04(void)
1394 {
1395   TestApplication application;
1396
1397   tet_infoline("Testing RenderTask Render Continuous using loading image\nPRE: Resource not ready\nPOST:continuous renders, no Finished signal");
1398
1399   // SETUP AN OFFSCREEN RENDER TASK
1400   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1401   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1402   drawTrace.Enable(true);
1403
1404   Actor rootActor = Actor::New();
1405   Stage::GetCurrent().Add( rootActor );
1406
1407   CameraActor offscreenCameraActor = CameraActor::New();
1408   Stage::GetCurrent().Add( offscreenCameraActor );
1409   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1410   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1411   Integration::ResourceId imageRequestId = imageRequest->GetId();
1412   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1413   Stage::GetCurrent().Add(secondRootActor);
1414
1415   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1416   bool finished = false;
1417   RenderTaskFinished renderTaskFinished( finished );
1418   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1419   application.SendNotification();
1420
1421   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1422   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1423   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1424
1425   // FINISH RESOURCE LOADING - expect 'continuous' renders to start, no finished signal
1426   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1427   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false ) );
1428   END_TEST;
1429 }
1430
1431
1432 int UtcDaliRenderTaskOnce01(void)
1433 {
1434   TestApplication application;
1435
1436   tet_infoline("Testing RenderTask Render Once GlSync, using loading image\nPRE: Resources not ready, Source not visible\nPOST: Finished signal sent once only");
1437
1438   // SETUP AN OFFSCREEN RENDER TASK
1439   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1440   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
1441   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1442   drawTrace.Enable(true);
1443
1444   Actor rootActor = Actor::New();
1445   Stage::GetCurrent().Add( rootActor );
1446
1447   CameraActor offscreenCameraActor = CameraActor::New();
1448   Stage::GetCurrent().Add( offscreenCameraActor );
1449   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1450   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1451   Integration::ResourceId imageRequestId = imageRequest->GetId();
1452   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1453
1454   Stage::GetCurrent().Add(secondRootActor);
1455   secondRootActor.SetVisible(false);
1456
1457   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, true);
1458   bool finished = false;
1459   RenderTaskFinished renderTaskFinished( finished );
1460   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1461   application.SendNotification();
1462
1463   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1464   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1465   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1466
1467   // MAKE SOURCE VISIBLE
1468   secondRootActor.SetVisible(true);
1469   application.SendNotification();
1470   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1471   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1472
1473   // FINISH RESOURCE LOADING - expect no rendering yet
1474   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1475   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1476   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
1477   DALI_TEST_CHECK( lastSyncObj != NULL );
1478
1479   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1480   application.GetPlatform().ClearReadyResources();
1481   sync.SetObjectSynced( lastSyncObj, true );
1482   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,   finished, false, true  ) );
1483   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false  ) );
1484   END_TEST;
1485 }
1486
1487 int UtcDaliRenderTaskOnce02(void)
1488 {
1489   TestApplication application;
1490
1491   tet_infoline("Testing RenderTask Render Once GlSync, using loading image. Switch from render always after ready to render once\n"
1492                "PRE: Render task ready, Image not loaded\n"
1493                "POST: Finished signal sent only once");
1494
1495   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
1496   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1497   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
1498   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1499   drawTrace.Enable(true);
1500
1501   Actor rootActor = Actor::New();
1502   Stage::GetCurrent().Add( rootActor );
1503
1504   CameraActor offscreenCameraActor = CameraActor::New();
1505   Stage::GetCurrent().Add( offscreenCameraActor );
1506   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1507   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1508   Integration::ResourceId imageRequestId = imageRequest->GetId();
1509   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1510   Stage::GetCurrent().Add(secondRootActor);
1511
1512   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1513   bool finished = false;
1514   RenderTaskFinished renderTaskFinished( finished );
1515   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1516   application.SendNotification();
1517
1518   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1519   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
1520   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
1521
1522   // FINISH RESOURCE LOADING
1523   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1524   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false ) );
1525   application.GetPlatform().ClearReadyResources();
1526   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false ) );
1527
1528   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
1529   application.SendNotification(); //         Input,    Expected  Input,    Expected
1530   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1531   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
1532   DALI_TEST_CHECK( lastSyncObj != NULL );
1533
1534   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1535   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1536   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1537   sync.SetObjectSynced( lastSyncObj, true );
1538   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true  ) );
1539   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false  ) );
1540
1541   END_TEST;
1542 }
1543
1544
1545 int UtcDaliRenderTaskOnce03(void)
1546 {
1547   TestApplication application;
1548
1549   tet_infoline("Testing RenderTask Render Once GlSync\n"
1550                "Switch from Render always after ready to render once with resources unready\n"
1551                "PRE: Everything ready to render\n"
1552                "POST: Finished signal sent once");
1553
1554   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
1555   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1556   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
1557   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1558   drawTrace.Enable(true);
1559
1560   Actor rootActor = Actor::New();
1561   Stage::GetCurrent().Add( rootActor );
1562
1563   CameraActor offscreenCameraActor = CameraActor::New();
1564   Stage::GetCurrent().Add( offscreenCameraActor );
1565   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1566   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1567   Integration::ResourceId imageRequestId = imageRequest->GetId();
1568   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1569   Stage::GetCurrent().Add(secondRootActor);
1570
1571   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1572   bool finished = false;
1573   RenderTaskFinished renderTaskFinished( finished );
1574   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1575   application.SendNotification();
1576
1577   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1578   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
1579   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
1580
1581   // CHANGE TO RENDER ONCE
1582   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
1583   application.SendNotification(); //         Input,    Expected  Input,    Expected
1584   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
1585   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
1586
1587   // FINISH RESOURCE LOADING
1588   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1589   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1590   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
1591   DALI_TEST_CHECK( lastSyncObj != NULL );
1592   application.GetPlatform().ClearReadyResources();
1593
1594   sync.SetObjectSynced( lastSyncObj, true );
1595   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true  ) );
1596   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false  ) );
1597
1598   END_TEST;
1599 }
1600
1601 #if 0
1602 //int UtcDaliRenderTaskOnce04(void)
1603 {
1604   TestApplication application;
1605
1606   tet_infoline("Testing RenderTask Render Once GlSync\n"
1607                "During RenderOnce, make ready resources unready before sending first finished signal\n"
1608                "PRE: Everything ready.\n"
1609                "POST: Finished signal sent only once");
1610
1611   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
1612   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1613   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
1614   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1615   drawTrace.Enable(true);
1616
1617   Actor rootActor = Actor::New();
1618   Stage::GetCurrent().Add( rootActor );
1619
1620   CameraActor offscreenCameraActor = CameraActor::New();
1621   Stage::GetCurrent().Add( offscreenCameraActor );
1622   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1623   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1624   Integration::ResourceId imageRequestId = imageRequest->GetId();
1625   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1626   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1627   application.Render();
1628
1629   Stage::GetCurrent().Add(secondRootActor);
1630   application.GetPlatform().ClearReadyResources();
1631
1632   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1633   bool finished = false;
1634   RenderTaskFinished renderTaskFinished( finished );
1635   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1636   application.SendNotification();
1637
1638   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1639   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1640   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1641
1642   // CHANGE TO RENDER ONCE, RESOURCES BECOME NOT READY
1643   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
1644
1645   // Doesn't work...
1646   ReloadImage(application, secondRootActor.GetImage());
1647   application.SendNotification(); //         Input,    Expected  Input,    Expected
1648
1649   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
1650   DALI_TEST_EQUALS( secondRootActor.GetImage().GetLoadingState(), Dali::ResourceLoading, TEST_LOCATION);
1651   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
1652
1653   // FINISH RESOURCE LOADING
1654   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1655   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1656   application.GetPlatform().ClearReadyResources();
1657   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
1658   DALI_TEST_CHECK( lastSyncObj != NULL );
1659
1660   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1661   sync.SetObjectSynced( lastSyncObj, true );
1662   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true  ) );
1663   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, true  ) );
1664
1665   // Finished rendering - expect no more renders, no more signals:
1666   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1667   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1668   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1669   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1670   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1671   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1672   END_TEST;
1673 }
1674 #endif
1675
1676 int UtcDaliRenderTaskOnce05(void)
1677 {
1678   TestApplication application;
1679
1680   tet_infoline("Testing RenderTask Render Once GLSync\n"
1681                "Render once, Second call to SetRefreshRate(ONCE) triggers only one more finished signal\n"
1682                "PRE: Everything ready\n"
1683                "POST: exactly 1 finished signal per call to SetRefreshRate(ONCE)");
1684
1685   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
1686   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1687   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
1688   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1689   drawTrace.Enable(true);
1690
1691   Actor rootActor = Actor::New();
1692   Stage::GetCurrent().Add( rootActor );
1693
1694   CameraActor offscreenCameraActor = CameraActor::New();
1695   Stage::GetCurrent().Add( offscreenCameraActor );
1696   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1697   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1698   Integration::ResourceId imageRequestId = imageRequest->GetId();
1699   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1700   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1701   application.Render();
1702   application.GetPlatform().ClearReadyResources();
1703
1704   Stage::GetCurrent().Add(secondRootActor);
1705
1706   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1707   bool finished = false;
1708   RenderTaskFinished renderTaskFinished( finished );
1709   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1710   application.SendNotification();
1711
1712   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1713   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1714   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false ) );
1715
1716   // CHANGE TO RENDER ONCE,
1717   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
1718   application.SendNotification();
1719   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1720   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
1721   DALI_TEST_CHECK( lastSyncObj != NULL );
1722
1723   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1724   sync.SetObjectSynced( lastSyncObj, true );
1725   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1726   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false  ) );
1727
1728   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
1729   application.SendNotification();
1730   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1731   lastSyncObj = sync.GetLastSyncObject();
1732   DALI_TEST_CHECK( lastSyncObj != NULL );
1733
1734   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1735   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1736   sync.SetObjectSynced( lastSyncObj, true );
1737   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1738   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false  ) );
1739   END_TEST;
1740 }
1741
1742 int UtcDaliRenderTaskOnce06(void)
1743 {
1744   TestApplication application;
1745
1746   tet_infoline("Testing RenderTask Render Once GLSync\n"
1747                "Render once, Call to SetRefreshRate(ONCE) in Finished signal callback triggers "
1748                "another render & another finished signal\n"
1749                "PRE: Everything ready\n"
1750                "POST: exactly 1 finished signal per call to SetRefreshRate(ONCE)");
1751
1752
1753   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
1754   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1755   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
1756   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1757   drawTrace.Enable(true);
1758
1759   Actor rootActor = Actor::New();
1760   Stage::GetCurrent().Add( rootActor );
1761
1762   CameraActor offscreenCameraActor = CameraActor::New();
1763   Stage::GetCurrent().Add( offscreenCameraActor );
1764   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1765   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1766   Integration::ResourceId imageRequestId = imageRequest->GetId();
1767   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1768   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1769   application.Render();
1770   application.GetPlatform().ClearReadyResources();
1771
1772   Stage::GetCurrent().Add(secondRootActor);
1773
1774   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1775   bool finished = false;
1776
1777   ConnectionTracker connectionTracker;
1778   RenderTaskFinishedRenderAgain renderTaskFinishedRenderAgain( finished );
1779   newTask.FinishedSignal().Connect( &connectionTracker, renderTaskFinishedRenderAgain );
1780
1781   application.SendNotification();
1782
1783   // Expect 2 frames to be drawn.
1784   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1785   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1786   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
1787   DALI_TEST_CHECK( lastSyncObj == NULL );
1788   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false ) );
1789
1790   // CHANGE TO RENDER ONCE,
1791   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
1792   application.SendNotification();
1793   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1794   lastSyncObj = sync.GetLastSyncObject();
1795   DALI_TEST_CHECK( lastSyncObj != NULL );
1796
1797   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1798   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1799
1800   sync.SetObjectSynced( lastSyncObj, true );
1801   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1802   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false  ) );
1803   application.SendNotification();
1804
1805   // Expect SetRefreshRate to have been called again
1806   // Prevent next finished signal calling refresh once again
1807   RenderTaskFinished renderTaskFinished( finished );
1808   connectionTracker.DisconnectAll();
1809   newTask.FinishedSignal().Connect( &connectionTracker, renderTaskFinished );
1810   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1811   lastSyncObj = sync.GetLastSyncObject();
1812   DALI_TEST_CHECK( lastSyncObj != NULL );
1813
1814   sync.SetObjectSynced( lastSyncObj, true );
1815   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1816   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false  ) );
1817   END_TEST;
1818 }
1819
1820
1821 int UtcDaliRenderTaskOnce07(void)
1822 {
1823   TestApplication application;
1824
1825   tet_infoline("Testing RenderTask Render Once GlSync\n"
1826                "SetRefreshRate(ONCE) again before first finished signal has been sent.\n"
1827                "PRE: resources ready\n"
1828                "POST: Only 1 finished signal sent.");
1829
1830   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
1831   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1832   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
1833   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1834   drawTrace.Enable(true);
1835
1836   Actor rootActor = Actor::New();
1837   Stage::GetCurrent().Add( rootActor );
1838
1839   CameraActor offscreenCameraActor = CameraActor::New();
1840   Stage::GetCurrent().Add( offscreenCameraActor );
1841   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1842   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1843   Integration::ResourceId imageRequestId = imageRequest->GetId();
1844   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1845   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1846   application.Render();
1847   application.GetPlatform().ClearReadyResources();
1848
1849   Stage::GetCurrent().Add(secondRootActor);
1850
1851   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1852   bool finished = false;
1853   RenderTaskFinished renderTaskFinished( finished );
1854   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1855   application.SendNotification();
1856
1857   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1858   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1859   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false ) );
1860
1861   // CHANGE TO RENDER ONCE,
1862   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
1863   application.SendNotification();
1864   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1865   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1866   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1867
1868   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
1869   application.SendNotification();
1870   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1871   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
1872   DALI_TEST_CHECK( lastSyncObj != NULL );
1873
1874   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1875   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1876   sync.SetObjectSynced( lastSyncObj, true );
1877   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1878   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false  ) );
1879
1880   END_TEST;
1881 }
1882
1883
1884
1885 int UtcDaliRenderTaskOnce08(void)
1886 {
1887   TestApplication application;
1888
1889   tet_infoline("Testing RenderTask Render Once GlSync\n"
1890                "SetRefreshRate(ONCE), resource load failed completes render task.\n"
1891                "PRE: resources not ready\n"
1892                "POST: Only 1 finished signal sent.");
1893
1894   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
1895   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1896   TestGlSyncAbstraction& sync = application.GetGlSyncAbstraction();
1897   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1898   drawTrace.Enable(true);
1899
1900   Actor rootActor = Actor::New();
1901   Stage::GetCurrent().Add( rootActor );
1902
1903   CameraActor offscreenCameraActor = CameraActor::New();
1904   Stage::GetCurrent().Add( offscreenCameraActor );
1905   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1906   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1907   Integration::ResourceId imageRequestId = imageRequest->GetId();
1908   Stage::GetCurrent().Add(secondRootActor);
1909
1910   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, true);
1911   bool finished = false;
1912   RenderTaskFinished renderTaskFinished( finished );
1913   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1914   application.SendNotification();
1915
1916   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1917   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
1918   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
1919
1920   // CHANGE TO RENDER ONCE,
1921   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
1922   application.SendNotification();
1923   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
1924   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
1925   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
1926
1927   tet_printf("  FailImageLoad\n");
1928
1929   FailImageLoad(application, imageRequestId); // Need to run Update again for this to complete
1930   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) ); // nothing to draw
1931   application.SendNotification();
1932
1933   // Drawing empty framebuffer, so will still get a GL sync
1934   Integration::GlSyncAbstraction::SyncObject* lastSyncObj = sync.GetLastSyncObject();
1935   DALI_TEST_CHECK( lastSyncObj != NULL );
1936
1937   // Expect finished signal, as all resources are complete
1938   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,   finished, true, false ) );
1939
1940   END_TEST;
1941 }
1942
1943
1944
1945 int UtcDaliRenderTaskOnceNoSync01(void)
1946 {
1947   TestApplication application;
1948
1949   tet_infoline("Testing RenderTask Render Once, using loading image\nPRE: Resources not ready, Source not visible\nPOST: Finished signal sent once only");
1950
1951   // SETUP AN OFFSCREEN RENDER TASK
1952   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1953   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
1954   drawTrace.Enable(true);
1955
1956   Actor rootActor = Actor::New();
1957   Stage::GetCurrent().Add( rootActor );
1958
1959   CameraActor offscreenCameraActor = CameraActor::New();
1960   Stage::GetCurrent().Add( offscreenCameraActor );
1961   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
1962   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
1963   Integration::ResourceId imageRequestId = imageRequest->GetId();
1964   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
1965
1966   Stage::GetCurrent().Add(secondRootActor);
1967   secondRootActor.SetVisible(false);
1968
1969   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ONCE, false);
1970   bool finished = false;
1971   RenderTaskFinished renderTaskFinished( finished );
1972   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
1973   application.SendNotification();
1974
1975   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
1976   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1977   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1978
1979   // MAKE SOURCE VISIBLE
1980   secondRootActor.SetVisible(true);
1981   application.SendNotification();
1982   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1983   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
1984
1985   // FINISH RESOURCE LOADING - expect immediate rendering yet
1986   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
1987   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
1988   application.GetPlatform().ClearReadyResources();
1989   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false ) );
1990   END_TEST;
1991 }
1992
1993 int UtcDaliRenderTaskOnceNoSync02(void)
1994 {
1995   TestApplication application;
1996
1997   tet_infoline("Testing RenderTask Render Once, using loading image. Switch from render always after ready to render once\n"
1998                "PRE: Render task ready, Image not loaded\n"
1999                "POST: Finished signal sent only once");
2000
2001   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2002   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2003   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2004   drawTrace.Enable(true);
2005
2006   Actor rootActor = Actor::New();
2007   Stage::GetCurrent().Add( rootActor );
2008
2009   CameraActor offscreenCameraActor = CameraActor::New();
2010   Stage::GetCurrent().Add( offscreenCameraActor );
2011   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
2012   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2013   Integration::ResourceId imageRequestId = imageRequest->GetId();
2014   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2015   Stage::GetCurrent().Add(secondRootActor);
2016
2017   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2018   bool finished = false;
2019   RenderTaskFinished renderTaskFinished( finished );
2020   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2021   application.SendNotification();
2022
2023   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2024   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
2025   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
2026
2027   // FINISH RESOURCE LOADING
2028   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2029   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false ) );
2030   application.GetPlatform().ClearReadyResources();
2031
2032   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2033   application.SendNotification(); //         Input,    Expected  Input,    Expected
2034   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
2035   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false  ) );
2036   END_TEST;
2037 }
2038
2039
2040 int UtcDaliRenderTaskOnceNoSync03(void)
2041 {
2042   TestApplication application;
2043
2044   tet_infoline("Testing RenderTask Render Once\n"
2045                "Switch from Render always after ready to render once with resources unready\n"
2046                "PRE: Everything ready to render\n"
2047                "POST: Finished signal sent once");
2048
2049   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2050   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2051   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2052   drawTrace.Enable(true);
2053
2054   Actor rootActor = Actor::New();
2055   Stage::GetCurrent().Add( rootActor );
2056
2057   CameraActor offscreenCameraActor = CameraActor::New();
2058   Stage::GetCurrent().Add( offscreenCameraActor );
2059   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
2060   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2061   Integration::ResourceId imageRequestId = imageRequest->GetId();
2062   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2063   Stage::GetCurrent().Add(secondRootActor);
2064
2065   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2066   bool finished = false;
2067   RenderTaskFinished renderTaskFinished( finished );
2068   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2069   application.SendNotification();
2070
2071   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2072   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
2073   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
2074
2075   // CHANGE TO RENDER ONCE
2076   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2077   application.SendNotification(); //         Input,    Expected  Input,    Expected
2078   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
2079   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
2080
2081   // FINISH RESOURCE LOADING
2082   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2083   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
2084   application.GetPlatform().ClearReadyResources();
2085   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true, false  ) );
2086   END_TEST;
2087 }
2088
2089 #if 0
2090 //int UtcDaliRenderTaskOnceNoSync04(void)
2091 {
2092   TestApplication application;
2093
2094   tet_infoline("Testing RenderTask Render Once\n"
2095                "During RenderOnce, make ready resources unready before sending first finished signal\n"
2096                "PRE: Everything ready.\n"
2097                "POST: Finished signal sent only once");
2098
2099   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2100   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2101   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2102   drawTrace.Enable(true);
2103
2104   Actor rootActor = Actor::New();
2105   Stage::GetCurrent().Add( rootActor );
2106
2107   CameraActor offscreenCameraActor = CameraActor::New();
2108   Stage::GetCurrent().Add( offscreenCameraActor );
2109   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
2110   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2111   Integration::ResourceId imageRequestId = imageRequest->GetId();
2112   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2113   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2114   application.Render();
2115   application.GetPlatform().ClearReadyResources();
2116
2117   Stage::GetCurrent().Add(secondRootActor);
2118
2119   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2120   bool finished = false;
2121   RenderTaskFinished renderTaskFinished( finished );
2122   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2123   application.SendNotification();
2124
2125   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2126   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
2127   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false ) );
2128
2129   // CHANGE TO RENDER ONCE, RESOURCES BECOME NOT READY
2130   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2131
2132   // Doesn't work...
2133   ReloadImage(application, secondRootActor.GetImage());
2134   application.SendNotification(); //         Input,    Expected  Input,    Expected
2135
2136   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
2137   DALI_TEST_EQUALS( secondRootActor.GetImage().GetLoadingState(), Dali::ResourceLoading, TEST_LOCATION);
2138   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
2139
2140   // FINISH RESOURCE LOADING
2141   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2142   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, true, true ) );
2143   application.GetPlatform().ClearReadyResources();
2144   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
2145   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true  ) );
2146   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
2147   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, false, true ) );
2148   END_TEST;
2149 }
2150 #endif
2151
2152 int UtcDaliRenderTaskOnceNoSync05(void)
2153 {
2154   TestApplication application;
2155
2156   tet_infoline("Testing RenderTask Render Once\n"
2157                "Render once, Second call to SetRefreshRate(ONCE) triggers only one more finished signal\n"
2158                "PRE: Everything ready\n"
2159                "POST: exactly 1 finished signal per call to SetRefreshRate(ONCE)");
2160
2161   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2162   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2163   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2164   drawTrace.Enable(true);
2165
2166   Actor rootActor = Actor::New();
2167   Stage::GetCurrent().Add( rootActor );
2168
2169   CameraActor offscreenCameraActor = CameraActor::New();
2170   Stage::GetCurrent().Add( offscreenCameraActor );
2171   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
2172   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2173   Integration::ResourceId imageRequestId = imageRequest->GetId();
2174   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2175   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2176   application.Render();
2177   application.GetPlatform().ClearReadyResources();
2178
2179   Stage::GetCurrent().Add(secondRootActor);
2180
2181   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2182   bool finished = false;
2183   RenderTaskFinished renderTaskFinished( finished );
2184   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2185   application.SendNotification();
2186
2187   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2188   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
2189   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false ) );
2190
2191   // CHANGE TO RENDER ONCE,
2192   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2193   application.SendNotification();
2194   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
2195   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false ) );
2196
2197   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2198   application.SendNotification();
2199   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
2200   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false ) );
2201   END_TEST;
2202 }
2203
2204 int UtcDaliRenderTaskOnceNoSync06(void)
2205 {
2206   TestApplication application;
2207
2208   tet_infoline("Testing RenderTask Render Once\n"
2209                "Render once, Call to SetRefreshRate(ONCE) in Finished signal callback triggers\n"
2210                "another render & another finished signal\n"
2211                "PRE: Everything ready\n"
2212                "POST: exactly 1 finished signal per call to SetRefreshRate(ONCE)");
2213
2214
2215   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2216   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2217   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2218   drawTrace.Enable(true);
2219
2220   Actor rootActor = Actor::New();
2221   Stage::GetCurrent().Add( rootActor );
2222
2223   CameraActor offscreenCameraActor = CameraActor::New();
2224   Stage::GetCurrent().Add( offscreenCameraActor );
2225   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
2226   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2227   Integration::ResourceId imageRequestId = imageRequest->GetId();
2228   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2229   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2230   application.Render();
2231   application.GetPlatform().ClearReadyResources();
2232
2233   Stage::GetCurrent().Add(secondRootActor);
2234
2235   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2236   bool finished = false;
2237
2238   ConnectionTracker connectionTracker;
2239   RenderTaskFinishedRenderAgain renderTaskFinishedRenderAgain( finished );
2240   newTask.FinishedSignal().Connect( &connectionTracker, renderTaskFinishedRenderAgain );
2241
2242   application.SendNotification();
2243
2244   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2245   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
2246   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false ) );
2247
2248   // CHANGE TO RENDER ONCE,
2249   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2250   application.SendNotification();
2251   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
2252   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false ) );
2253
2254   // Expect SetRefreshRate to have been called again
2255   // Prevent next finished signal calling refresh once again
2256   RenderTaskFinished renderTaskFinished( finished );
2257   connectionTracker.DisconnectAll();
2258   newTask.FinishedSignal().Connect( &connectionTracker, renderTaskFinished );
2259
2260   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
2261   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false ) );
2262   END_TEST;
2263 }
2264
2265
2266 int UtcDaliRenderTaskOnceNoSync07(void)
2267 {
2268   TestApplication application;
2269
2270   tet_infoline("Testing RenderTask Render Once\n"
2271                "SetRefreshRate(ONCE) again before first finished signal has been sent.\n"
2272                "PRE: resources ready\n"
2273                "POST: Only 1 finished signal sent.");
2274
2275   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2276   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2277   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2278   drawTrace.Enable(true);
2279
2280   Actor rootActor = Actor::New();
2281   Stage::GetCurrent().Add( rootActor );
2282
2283   CameraActor offscreenCameraActor = CameraActor::New();
2284   Stage::GetCurrent().Add( offscreenCameraActor );
2285   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
2286   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2287   Integration::ResourceId imageRequestId = imageRequest->GetId();
2288   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2289   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2290   application.Render();
2291   application.GetPlatform().ClearReadyResources();
2292
2293   Stage::GetCurrent().Add(secondRootActor);
2294
2295   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2296   bool finished = false;
2297   RenderTaskFinished renderTaskFinished( finished );
2298   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2299   application.SendNotification();
2300
2301   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2302   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
2303   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, false ) );
2304
2305   // CHANGE TO RENDER ONCE,
2306   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2307   application.SendNotification();
2308   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
2309   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false ) );
2310
2311   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2312   application.SendNotification();
2313   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,    finished, false, true ) );
2314   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,   finished, true,  false ) );
2315   END_TEST;
2316 }
2317
2318 int UtcDaliRenderTaskOnceNoSync08(void)
2319 {
2320   TestApplication application;
2321
2322   tet_infoline("Testing RenderTask Render Once\n"
2323                "SetRefreshRate(ONCE), resource load failed, completes render task.\n"
2324                "PRE: resources not ready\n"
2325                "POST: Only 1 finished signal sent.");
2326
2327   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2328   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2329   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2330   drawTrace.Enable(true);
2331
2332   Actor rootActor = Actor::New();
2333   Stage::GetCurrent().Add( rootActor );
2334
2335   CameraActor offscreenCameraActor = CameraActor::New();
2336   Stage::GetCurrent().Add( offscreenCameraActor );
2337   ImageActor secondRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
2338   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2339   Integration::ResourceId imageRequestId = imageRequest->GetId();
2340   Stage::GetCurrent().Add(secondRootActor);
2341
2342   RenderTask newTask = CreateRenderTask(application, offscreenCameraActor, rootActor, secondRootActor, RenderTask::REFRESH_ALWAYS, false);
2343   bool finished = false;
2344   RenderTaskFinished renderTaskFinished( finished );
2345   newTask.FinishedSignal().Connect( &application, renderTaskFinished );
2346   application.SendNotification();
2347
2348   // START PROCESS/RENDER                    Input,     Expected  Input,    Expected
2349   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
2350   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
2351
2352   // CHANGE TO RENDER ONCE,
2353   newTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
2354   application.SendNotification();
2355   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
2356   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
2357   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) );
2358
2359   FailImageLoad(application, imageRequestId); // Need to run Update again for this to complete
2360   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, false, true ) ); // nothing to draw
2361   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,    finished, true,  false  ) );
2362
2363   END_TEST;
2364 }
2365
2366
2367
2368 int UtcDaliRenderTaskOnceChain01(void)
2369 {
2370   TestApplication application;
2371
2372   tet_infoline("Testing RenderTask Render Once Chained render tasks\n"
2373                "SetRefreshRate(ONCE), resource load completes, both render tasks render.\n"
2374                "PRE: resources not ready\n"
2375                "POST: 2 finished signals sent.");
2376
2377   // SETUP A CONTINUOUS OFFSCREEN RENDER TASK
2378   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2379   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
2380   drawTrace.Enable(true);
2381
2382   Actor defaultRootActor = Actor::New(); // Root for default RT
2383   Stage::GetCurrent().Add( defaultRootActor );
2384
2385   CameraActor offscreenCameraActor = CameraActor::New();
2386   Stage::GetCurrent().Add( offscreenCameraActor );
2387   ImageActor firstRootActor = CreateLoadingImage(application, "aFile.jpg", Image::Immediate, Image::Unused);
2388   Integration::ResourceRequest* imageRequest = application.GetPlatform().GetRequest();
2389   Integration::ResourceId imageRequestId = imageRequest->GetId();
2390   Integration::ResourceTypeId imageType  = imageRequest->GetType()->id;
2391   Stage::GetCurrent().Add(firstRootActor);
2392
2393   // first render task
2394   RenderTask firstTask = CreateRenderTask(application, offscreenCameraActor, defaultRootActor, firstRootActor, RenderTask::REFRESH_ONCE, false);
2395   bool firstFinished = false;
2396   RenderTaskFinished renderTask1Finished( firstFinished );
2397   firstTask.FinishedSignal().Connect( &application, renderTask1Finished );
2398
2399   // Second render task
2400   FrameBufferImage fbo = firstTask.GetTargetFrameBuffer();
2401   ImageActor secondRootActor = ImageActor::New( fbo );
2402   Stage::GetCurrent().Add(secondRootActor);
2403   RenderTask secondTask = CreateRenderTask(application, offscreenCameraActor, defaultRootActor, secondRootActor, RenderTask::REFRESH_ONCE, false);
2404   bool secondFinished = false;
2405   RenderTaskFinished renderTask2Finished( secondFinished );
2406   secondTask.FinishedSignal().Connect( &application, renderTask2Finished );
2407
2408   application.SendNotification();
2409
2410   // START PROCESS/RENDER                    Input,    Expected  Input,    Expected
2411   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,  firstFinished, false, true ) );
2412   DALI_TEST_CHECK( secondFinished == false );
2413   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,  firstFinished, false, true ) );
2414   DALI_TEST_CHECK( secondFinished == false );
2415
2416   CompleteImageLoad(application, imageRequestId, imageType); // Need to run update again for this to complete
2417   DALI_TEST_CHECK( UpdateRender(application, drawTrace, true,  firstFinished, false, true ) );
2418   DALI_TEST_CHECK( secondFinished == false );
2419   application.GetPlatform().ClearReadyResources();
2420
2421   DALI_TEST_CHECK( UpdateRender(application, drawTrace, false,  firstFinished, true,  false ) );
2422   DALI_TEST_CHECK( secondFinished == true );
2423
2424   END_TEST;
2425 }
2426
2427 int UtcDaliRenderTaskProperties(void)
2428 {
2429   TestApplication application;
2430
2431   RenderTask task = Stage::GetCurrent().GetRenderTaskList().CreateTask();
2432
2433   Property::IndexContainer indices;
2434   task.GetPropertyIndices( indices );
2435   DALI_TEST_CHECK( ! indices.empty() );
2436   DALI_TEST_EQUALS( indices.size(), task.GetPropertyCount(), TEST_LOCATION );
2437   END_TEST;
2438 }
2439
2440 int UtcDaliRenderTaskSetScreenToFrameBufferMappingActor(void)
2441 {
2442   TestApplication application;
2443   tet_infoline("Testing RenderTask::SetScreenToFrameBufferMappingActor ");
2444
2445   Stage stage = Stage::GetCurrent();
2446   Size stageSize = stage.GetSize();
2447   Actor mappingActor = Actor::New();
2448   Vector2 scale( 0.6f, 0.75f);
2449   Vector2 offset( stageSize.x*0.1f, stageSize.y*0.15f);
2450   mappingActor.SetSize( stageSize * scale );
2451   mappingActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2452   mappingActor.SetPosition( offset.x, offset.y );
2453   stage.Add( mappingActor );
2454
2455   Actor offscreenActor = Actor::New();
2456   offscreenActor.SetSize( stageSize );
2457   offscreenActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2458   stage.Add( offscreenActor );
2459
2460   RenderTaskList taskList = stage.GetRenderTaskList();
2461   RenderTask renderTask = taskList.CreateTask();
2462   FrameBufferImage frameBufferImage =  FrameBufferImage::New(stageSize.width*scale.x, stageSize.height*scale.y, Pixel::A8, Image::Never);
2463   renderTask.SetSourceActor( offscreenActor );
2464   renderTask.SetExclusive( true );
2465   renderTask.SetInputEnabled( true );
2466   renderTask.SetTargetFrameBuffer( frameBufferImage );
2467   renderTask.SetRefreshRate( RenderTask::REFRESH_ONCE );
2468   renderTask.SetScreenToFrameBufferMappingActor( mappingActor );
2469   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2470
2471   // Render and notify
2472   application.SendNotification();
2473   application.Render();
2474   application.Render();
2475   application.SendNotification();
2476
2477   Vector2 screenCoordinates( stageSize.x * 0.05f, stageSize.y * 0.05f );
2478   Dali::HitTestAlgorithm::Results results;
2479   DALI_TEST_CHECK( !results.actor );
2480   DALI_TEST_EQUALS( Vector2::ZERO, results.actorCoordinates, 0.1f, TEST_LOCATION );
2481   // miss expected, results not changed
2482   DALI_TEST_CHECK( false == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
2483   DALI_TEST_CHECK( !results.actor );
2484   DALI_TEST_EQUALS( Vector2::ZERO, results.actorCoordinates, 0.1f, TEST_LOCATION );
2485
2486   screenCoordinates.x = stageSize.x * 0.265f;
2487   screenCoordinates.y = stageSize.y * 0.33f;
2488   results.actor = Actor();
2489   results.actorCoordinates = Vector2::ZERO;
2490   // hit expected, results changed
2491   DALI_TEST_CHECK( true == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
2492   DALI_TEST_CHECK( results.actor  == offscreenActor );
2493   DALI_TEST_EQUALS( (screenCoordinates-offset)/scale , results.actorCoordinates, 0.1f, TEST_LOCATION );
2494
2495   screenCoordinates.x = stageSize.x * 0.435f;
2496   screenCoordinates.y = stageSize.y * 0.52f;
2497   // hit expected, results changed
2498   DALI_TEST_CHECK( true == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
2499   DALI_TEST_CHECK( results.actor  == offscreenActor );
2500   const Vector2 expectedCoordinates = (screenCoordinates-offset)/scale;
2501   DALI_TEST_EQUALS( expectedCoordinates , results.actorCoordinates, 0.1f, TEST_LOCATION );
2502
2503   screenCoordinates.x = stageSize.x * 0.65f;
2504   screenCoordinates.y = stageSize.y * 0.95f;
2505   // miss expected, results not changed
2506   DALI_TEST_CHECK( false == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
2507   DALI_TEST_CHECK( results.actor  == offscreenActor );
2508   DALI_TEST_EQUALS( expectedCoordinates , results.actorCoordinates, 0.1f, TEST_LOCATION );
2509   END_TEST;
2510 }