Bug fix which makes applications crash when adding a renderer to an on stage actor
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-RenderableActor.cpp
index 6b0441e..25ebaf9 100644 (file)
@@ -19,7 +19,6 @@
 
 #include <stdlib.h>
 #include <dali/public-api/dali-core.h>
-
 #include <dali/integration-api/events/touch-event-integ.h>
 #include <dali-test-suite-utils.h>
 
@@ -113,7 +112,7 @@ int UtcDaliRenderableActorSetSortModifier(void)
   //Verify through layer SetSortFunction
   gIsActor1SortModifierCorrect = false;
   gIsActor2SortModifierCorrect = false;
-  BitmapImage img = BitmapImage::New( 1,1 );
+  BufferImage img = BufferImage::New( 1,1 );
   // create two transparent actors so there is something to sort
   ImageActor actor1 = ImageActor::New( img );
   ImageActor actor2 = ImageActor::New( img );
@@ -182,7 +181,7 @@ int UtcDaliRenderableActorSetCullFace(void)
 
   tet_infoline("Testing Dali::RenderableActor::SetCullFace()");
 
-  BitmapImage img = BitmapImage::New( 1,1 );
+  BufferImage img = BufferImage::New( 1,1 );
   ImageActor actor = ImageActor::New( img );
   ImageActor actor2 = ImageActor::New( img );
 
@@ -303,9 +302,10 @@ int UtcDaliRenderableActorGetCullFace(void)
 
   DALI_TEST_CHECK( CullNone == imageActor.GetCullFace() );
 
-  MeshActor meshActor = MeshActor::New();
+  imageActor.SetCullFace( CullBack );
+
+  DALI_TEST_CHECK( CullBack == imageActor.GetCullFace() );
 
-  DALI_TEST_CHECK( CullBack == meshActor.GetCullFace() );
   END_TEST;
 }
 
@@ -316,7 +316,7 @@ int UtcDaliRenderableActorSetGetBlendFunc(void)
 
   tet_infoline("Testing Dali::RenderableActor::UtcDaliRenderableActorSetGetBlendFunc()");
 
-  BitmapImage img = BitmapImage::New( 1,1 );
+  BufferImage img = BufferImage::New( 1,1 );
   ImageActor actor = ImageActor::New( img );
   Stage::GetCurrent().Add( actor );
   application.SendNotification();
@@ -336,7 +336,7 @@ int UtcDaliRenderableActorSetGetBlendFunc(void)
   }
 
   // Set to non-default values
-  actor.SetBlendFunc( BlendingFactor::ONE_MINUS_SRC_COLOR, BlendingFactor::SRC_ALPHA_SATURATE );
+  actor.SetBlendFunc( BlendingFactor::ONE_MINUS_SRC_COLOR, BlendingFactor::SRC_ALPHA_SATURATE, BlendingFactor::ONE_MINUS_SRC_COLOR, BlendingFactor::SRC_ALPHA_SATURATE );
 
   // Test that Set was successful
   {
@@ -386,90 +386,13 @@ int UtcDaliRenderableActorSetGetBlendFunc(void)
   END_TEST;
 }
 
-int UtcDaliRenderableActorSetGetBlendEquation(void)
-{
-  TestApplication application;
-  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
-
-  tet_infoline("Testing Dali::RenderableActor::SetBlendEquation()");
-
-  BitmapImage img = BitmapImage::New( 1,1 );
-  ImageActor actor = ImageActor::New( img );
-  Stage::GetCurrent().Add( actor );
-  application.SendNotification();
-  application.Render();
-
-  // Test the defaults as documented int blending.h
-  {
-    BlendingEquation::Type equationRgb( BlendingEquation::SUBTRACT );
-    BlendingEquation::Type equationAlpha( BlendingEquation::SUBTRACT );
-    actor.GetBlendEquation( equationRgb, equationAlpha );
-    DALI_TEST_EQUALS( BlendingEquation::ADD, equationRgb, TEST_LOCATION );
-    DALI_TEST_EQUALS( BlendingEquation::ADD, equationAlpha, TEST_LOCATION );
-  }
-
-  // Test the single blending equation setting
-  {
-    actor.SetBlendEquation( BlendingEquation::REVERSE_SUBTRACT );
-    BlendingEquation::Type equationRgba( BlendingEquation::SUBTRACT );
-    actor.GetBlendEquation( equationRgba, equationRgba );
-    DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationRgba, TEST_LOCATION );
-  }
-
-  actor.SetBlendEquation( BlendingEquation::REVERSE_SUBTRACT, BlendingEquation::REVERSE_SUBTRACT );
-
-  // Test that Set was successful
-  {
-    BlendingEquation::Type equationRgb( BlendingEquation::SUBTRACT );
-    BlendingEquation::Type equationAlpha( BlendingEquation::SUBTRACT );
-    actor.GetBlendEquation( equationRgb, equationAlpha );
-    DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
-    DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION );
-  }
-
-  // Render & check GL commands
-  application.SendNotification();
-  application.Render();
-  DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(),   TEST_LOCATION );
-  DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION );
-  END_TEST;
-}
-
-int UtcDaliRenderableActorSetGetBlendColor(void)
-{
-  TestApplication application;
-  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
-
-  tet_infoline("Testing Dali::RenderableActor::SetBlendColor()");
-
-  BitmapImage img = BitmapImage::New( 1,1 );
-  ImageActor actor = ImageActor::New( img );
-  Stage::GetCurrent().Add( actor );
-  application.SendNotification();
-  application.Render();
-
-  // Test the defaults as documented int blending.h
-  DALI_TEST_EQUALS( Vector4::ZERO, actor.GetBlendColor(), TEST_LOCATION );
-
-  actor.SetBlendColor( Color::RED );
-
-  // Test that Set was successful
-  DALI_TEST_EQUALS( Color::RED, actor.GetBlendColor(), TEST_LOCATION );
-
-  // Render & check GL commands
-  application.SendNotification();
-  application.Render();
-  DALI_TEST_EQUALS( Color::RED, glAbstraction.GetLastBlendColor(),   TEST_LOCATION );
-  END_TEST;
-}
-
 int UtcDaliRenderableActorSetGetAlpha(void)
 {
   TestApplication application;
 
   tet_infoline("Testing Dali::RenderableActor::SetGetAlpha()");
 
-  BitmapImage img = BitmapImage::New( 1,1 );
+  BufferImage img = BufferImage::New( 1,1 );
   ImageActor actor = ImageActor::New( img );
   Stage::GetCurrent().Add( actor );
   application.SendNotification();
@@ -552,7 +475,7 @@ int UtcDaliRenderableActorSetFilterMode(void)
 
   tet_infoline("Testing Dali::RenderableActor::SetFilterMode()");
 
-  BitmapImage img = BitmapImage::New( 1,1 );
+  BufferImage img = BufferImage::New( 1,1 );
   ImageActor actor = ImageActor::New( img );
 
   actor.SetSize(100.0f, 100.0f);
@@ -732,7 +655,7 @@ int UtcDaliRenderableActorSetFilterMode(void)
 int UtcDaliRenderableActorSetShaderEffect(void)
 {
   TestApplication application;
-  BitmapImage img = BitmapImage::New( 1,1 );
+  BufferImage img = BufferImage::New( 1,1 );
   ImageActor actor = ImageActor::New( img );
   Stage::GetCurrent().Add( actor );
 
@@ -821,7 +744,7 @@ int UtcDaliSetShaderEffectRecursively(void)
    *       actor3 imageactor1
    * imageactor2
    */
-  BitmapImage img = BitmapImage::New( 1,1 );
+  BufferImage img = BufferImage::New( 1,1 );
   ImageActor actor1 = ImageActor::New( img );
   Actor actor2 = Actor::New();
   actor1.Add( actor2 );
@@ -894,3 +817,184 @@ int UtcDaliSetShaderEffectRecursively(void)
   END_TEST;
 }
 
+int UtcDaliRenderableActorTestClearCache01(void)
+{
+  // Testing the framebuffer state caching in frame-buffer-state-caching.cpp
+  TestApplication application;
+
+  tet_infoline("Testing Dali::RenderableActor::ClearCache01()");
+
+  BufferImage img = BufferImage::New( 1,1 );
+  ImageActor actor = ImageActor::New( img );
+
+  actor.SetParentOrigin(ParentOrigin::CENTER);
+  actor.SetAnchorPoint(AnchorPoint::CENTER);
+
+  Stage::GetCurrent().Add(actor);
+
+  /**************************************************************/
+  // Flush the queue and render once
+  application.SendNotification();
+  application.Render();
+
+  // There should be a single call to Clear
+  DALI_TEST_EQUALS( application.GetGlAbstraction().GetClearCountCalled() , 1u, TEST_LOCATION );
+
+  // the last set clear mask should be COLOR, DEPTH & STENCIL which occurs at the start of each frame
+  GLbitfield mask = application.GetGlAbstraction().GetLastClearMask();
+  DALI_TEST_CHECK( mask & GL_DEPTH_BUFFER_BIT );
+  DALI_TEST_CHECK( mask & GL_STENCIL_BUFFER_BIT );
+  DALI_TEST_CHECK( mask & GL_COLOR_BUFFER_BIT );
+
+  END_TEST;
+}
+
+int UtcDaliRenderableActorTestClearCache02(void)
+{
+  // Testing the framebuffer state caching in frame-buffer-state-caching.cpp
+  TestApplication application;
+
+  tet_infoline("Testing Dali::RenderableActor::ClearCache02()");
+
+  // use RGB so alpha is disabled and the actors are drawn opaque
+  BufferImage img = BufferImage::New( 10,10 ,Pixel::RGB888 );
+
+  // Without caching DALi perform clears in the following places
+  // Root
+  // | glClear #1 ( everything at start of frame )
+  // |
+  // |
+  // | glClear #2 ( start of layer with opaque actors )
+  // | ----> Layer1
+  // |     -> Actor 1 ( opaque )
+  // |     -> Actor 2 ( opaque )
+  // |
+  // |
+  // | glClear  #3 ( start of layer with opaque actors )
+  // |----> Layer 2
+  // |     -> Actor 3 ( opaque )
+  // |     -> Actor 4 ( opaque )
+  //
+  // With caching enabled glClear should only be called twice, at points #1 and #3.
+  // At #1 with depth, color and stencil cleared
+  // At #3 with depth cleared
+  // #2 is not required because the buffer has already been cleared at #1
+
+  Layer layer1 = Layer::New();
+  layer1.Add( ImageActor::New( img ) );
+  layer1.Add( ImageActor::New( img ) );
+
+  Layer layer2 = Layer::New();
+  layer2.Add( ImageActor::New( img ) );
+  layer2.Add( ImageActor::New( img ) );
+
+  Stage::GetCurrent().Add( layer1 );
+  Stage::GetCurrent().Add( layer2 );
+
+  /**************************************************************/
+
+  // Flush the queue and render once
+  application.SendNotification();
+  application.Render();
+
+  // There should be a 2 calls to Clear
+  DALI_TEST_EQUALS( application.GetGlAbstraction().GetClearCountCalled() , 2u, TEST_LOCATION );
+
+  // the last set clear mask should be  DEPTH & STENCIL & COLOR
+  GLbitfield mask = application.GetGlAbstraction().GetLastClearMask();
+
+  tet_printf(" clear count = %d \n",  application.GetGlAbstraction().GetClearCountCalled() );
+
+  // The last clear should just be DEPTH BUFFER, not color and stencil which were cleared at the start of the frame
+  DALI_TEST_CHECK( mask & GL_DEPTH_BUFFER_BIT );
+  DALI_TEST_CHECK( ! ( mask & GL_COLOR_BUFFER_BIT ) );
+  DALI_TEST_CHECK( ! ( mask & GL_STENCIL_BUFFER_BIT ) );
+
+  END_TEST;
+}
+
+int UtcDaliRenderableActorTestClearCache03(void)
+{
+  // Testing the framebuffer state caching in frame-buffer-state-caching.cpp
+  TestApplication application;
+
+  tet_infoline("Testing Dali::RenderableActor::ClearCache03()");
+
+  // use RGB so alpha is disabled and the actors are drawn opaque
+  BufferImage img = BufferImage::New( 10,10 ,Pixel::RGB888 );
+
+  // Without caching DALi perform clears in the following places
+  // Root
+  // | 1-## glClear ( COLOR, DEPTH, STENCIL )
+  // |
+  // | ----> Layer1
+  // |     2-##  glClear  ( STENCIL )
+  // |     -> Actor 1 ( stencil )
+  // |     3-##  glClear  ( DEPTH )
+  // |     -> Actor 2 ( opaque )  // need 2 opaque actors to bypass optimisation of turning off depth test
+  // |     -> Actor 3 ( opaque )
+  // |
+  // |
+  // |----> Layer 2
+  // |     4-##  glClear  ( STENCIL )
+  // |     -> Actor 4 ( stencil )
+  // |     5-##  glClear  ( DEPTH )
+  // |     -> Actor 5 ( opaque )  // need 2 opaque actors to bypass optimisation of turning off depth test
+  // |     -> Actor 6 ( opaque )
+  //
+  // With caching enabled glClear will not be called at ## 2 and ## 3 ( because those buffers are already clear).
+  //
+  // @TODO Add further optimisation to look-ahead in the render-list to see if
+  // When performing STENCIL clear, check if there another layer after it.
+  // If there is, combine the STENCIL with a DEPTH clear.
+  //
+
+  Layer layer1 = Layer::New();
+  ImageActor actor1 =  ImageActor::New( img );
+  ImageActor actor2 =  ImageActor::New( img );
+  ImageActor actor3 =  ImageActor::New( img );
+
+  actor2.SetDrawMode( DrawMode::STENCIL );
+
+  layer1.Add( actor1 );
+  layer1.Add( actor2 );
+  layer1.Add( actor3 );
+
+  Layer layer2 = Layer::New();
+  ImageActor actor4 =  ImageActor::New( img );
+  ImageActor actor5 =  ImageActor::New( img );
+  ImageActor actor6 =  ImageActor::New( img );
+
+  actor4.SetDrawMode( DrawMode::STENCIL );
+
+  layer2.Add( actor4 );
+  layer2.Add( actor5 );
+  layer2.Add( actor6 );
+
+  Stage::GetCurrent().Add( layer1 );
+  Stage::GetCurrent().Add( layer2 );
+
+
+  /**************************************************************/
+
+  // Flush the queue and render once
+  application.SendNotification();
+  application.Render();
+
+  // There should be a 3 calls to Clear ( one for everything, one for stencil, one for depth buffer).
+  DALI_TEST_EQUALS( application.GetGlAbstraction().GetClearCountCalled() , 3u, TEST_LOCATION );
+
+  // the last set clear mask should be  DEPTH & STENCIL & COLOR
+  GLbitfield mask = application.GetGlAbstraction().GetLastClearMask();
+
+  tet_printf(" clear count = %d \n",  application.GetGlAbstraction().GetClearCountCalled() );
+  tet_printf(" clear mask  = %x \n",  mask);
+
+  // The last clear should just be DEPTH BUFFER and stencil
+  DALI_TEST_CHECK(  !( mask & GL_COLOR_BUFFER_BIT ) );
+  DALI_TEST_CHECK(  !( mask & GL_STENCIL_BUFFER_BIT ) );
+  DALI_TEST_CHECK(  mask & GL_DEPTH_BUFFER_BIT );
+
+
+  END_TEST;
+}