[Tizen] Implement partial update
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Actor.cpp
old mode 100644 (file)
new mode 100755 (executable)
index 7ab3422..7ced69b
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -263,6 +263,23 @@ struct ChildOrderChangedFunctor
   Actor& mActor;
 };
 
+struct CulledPropertyNotificationFunctor
+{
+  CulledPropertyNotificationFunctor( bool& signalCalled, PropertyNotification& propertyNotification )
+  : mSignalCalled( signalCalled ),
+    mPropertyNotification( propertyNotification )
+  { }
+
+  void operator()( PropertyNotification& source )
+  {
+    mSignalCalled  = true;
+    mPropertyNotification = source;
+  }
+
+  bool& mSignalCalled;
+  PropertyNotification& mPropertyNotification;
+};
+
 } // anonymous namespace
 
 
@@ -1252,6 +1269,29 @@ int UtcDaliActorGetCurrentSizeImmediate(void)
   END_TEST;
 }
 
+int UtcDaliActorCalculateScreenExtents(void)
+{
+  TestApplication application;
+
+  Actor actor = Actor::New();
+
+  actor.SetPosition(Vector3(2.0f, 2.0f, 16.0f));
+  actor.SetSize(Vector3{ 1.0f, 1.0f, 1.0f });
+
+  application.SendNotification();
+  application.Render();
+
+  auto expectedExtent = Rect<>{ -0.5f, -0.5f, 1.0f, 1.0f };
+  auto actualExtent = DevelActor::CalculateScreenExtents( actor );
+  DALI_TEST_EQUALS( expectedExtent.x, actualExtent.x, Math::MACHINE_EPSILON_10000, TEST_LOCATION );
+  DALI_TEST_EQUALS( expectedExtent.y, actualExtent.y, Math::MACHINE_EPSILON_10000, TEST_LOCATION );
+  DALI_TEST_EQUALS( expectedExtent.width, actualExtent.width, Math::MACHINE_EPSILON_10000, TEST_LOCATION );
+  DALI_TEST_EQUALS( expectedExtent.height, actualExtent.height, Math::MACHINE_EPSILON_10000, TEST_LOCATION );
+
+  Stage::GetCurrent().Remove( actor );
+  END_TEST;
+}
+
 // SetPosition(float x, float y)
 int UtcDaliActorSetPosition01(void)
 {
@@ -1536,55 +1576,6 @@ int UtcDaliActorGetCurrentWorldPosition(void)
   END_TEST;
 }
 
-int UtcDaliActorInheritPosition(void)
-{
-  tet_infoline("Testing Actor::SetPositionInheritanceMode");
-  TestApplication application;
-
-  Actor parent = Actor::New();
-  Vector3 parentPosition( 1.0f, 2.0f, 3.0f );
-  parent.SetPosition( parentPosition );
-  parent.SetParentOrigin( ParentOrigin::CENTER );
-  parent.SetAnchorPoint( AnchorPoint::CENTER );
-  Stage::GetCurrent().Add( parent );
-
-  Actor child = Actor::New();
-  child.SetParentOrigin( ParentOrigin::CENTER );
-  child.SetAnchorPoint( AnchorPoint::CENTER );
-  Vector3 childPosition( 10.0f, 11.0f, 12.0f );
-  child.SetPosition( childPosition );
-  parent.Add( child );
-
-  // The actors should not have a world position yet
-  DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
-  DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), Vector3::ZERO, TEST_LOCATION );
-
-  // first test default, which is to inherit position
-  DALI_TEST_EQUALS( child.GetPositionInheritanceMode(), Dali::INHERIT_PARENT_POSITION, TEST_LOCATION );
-  application.SendNotification();
-  application.Render(0); // should only really call Update as Render is not required to update scene
-  DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
-  DALI_TEST_EQUALS( child.GetCurrentPosition(), childPosition, TEST_LOCATION );
-  DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
-  DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), parentPosition + childPosition, TEST_LOCATION );
-
-
-  //Change child position
-  Vector3 childOffset( -1.0f, 1.0f, 0.0f );
-  child.SetPosition( childOffset );
-
-  // Change inheritance mode to not inherit
-  child.SetPositionInheritanceMode( Dali::DONT_INHERIT_POSITION );
-  DALI_TEST_EQUALS( child.GetPositionInheritanceMode(), Dali::DONT_INHERIT_POSITION, TEST_LOCATION );
-  application.SendNotification();
-  application.Render(0); // should only really call Update as Render is not required to update scene
-  DALI_TEST_EQUALS( parent.GetCurrentPosition(), parentPosition, TEST_LOCATION );
-  DALI_TEST_EQUALS( child.GetCurrentPosition(), childOffset, TEST_LOCATION );
-  DALI_TEST_EQUALS( parent.GetCurrentWorldPosition(), parentPosition, TEST_LOCATION );
-  DALI_TEST_EQUALS( child.GetCurrentWorldPosition(), childOffset, TEST_LOCATION );
-  END_TEST;
-}
-
 int UtcDaliActorSetInheritPosition(void)
 {
   tet_infoline("Testing Actor::SetInheritPosition");
@@ -1643,6 +1634,41 @@ int UtcDaliActorSetInheritPosition(void)
   END_TEST;
 }
 
+int UtcDaliActorInheritOpacity(void)
+{
+  tet_infoline("Testing Actor::Inherit Opacity");
+  TestApplication application;
+
+  Actor parent = Actor::New();
+  Actor child = Actor::New();
+  parent.Add( child );
+  Stage::GetCurrent().Add( parent );
+
+  DALI_TEST_EQUALS( parent.GetProperty( Actor::Property::COLOR_ALPHA ).Get<float>(), 1.0f, 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( child.GetProperty( Actor::Property::COLOR_ALPHA ).Get<float>(), 1.0f, 0.0001f, TEST_LOCATION );
+
+  // flush the queue and render once
+  application.SendNotification();
+  application.Render();
+
+  parent.SetOpacity( 0.1f );
+
+  DALI_TEST_EQUALS( parent.GetProperty( Actor::Property::COLOR_ALPHA ).Get<float>(), 0.1f, 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( child.GetProperty( Actor::Property::COLOR_ALPHA ).Get<float>(), 1.0f, 0.0001f, TEST_LOCATION );
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( parent.GetProperty( Actor::Property::WORLD_COLOR ).Get<Vector4>(), Vector4(1.f, 1.f, 1.f, 0.1f), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( parent.GetCurrentProperty( Actor::Property::COLOR_ALPHA ).Get<float>(), 0.1f, 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( parent.GetCurrentProperty( Actor::Property::WORLD_COLOR ).Get<Vector4>(), Vector4(1.f, 1.f, 1.f, 0.1f), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( child.GetProperty( Actor::Property::WORLD_COLOR ).Get<Vector4>(), Vector4(1.f, 1.f, 1.f, 0.1f), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( child.GetCurrentProperty( Actor::Property::WORLD_COLOR ).Get<Vector4>(), Vector4(1.f, 1.f, 1.f, 0.1f), 0.0001f, TEST_LOCATION );
+  DALI_TEST_EQUALS( child.GetCurrentProperty( Actor::Property::COLOR_ALPHA ).Get<float>(), 1.f, 0.0001f, TEST_LOCATION );
+
+  END_TEST;
+}
+
 // SetOrientation(float angleRadians, Vector3 axis)
 int UtcDaliActorSetOrientation01(void)
 {
@@ -3245,7 +3271,6 @@ const PropertyStringIndex PROPERTY_TABLE[] =
   { "inheritOrientation",       Actor::Property::INHERIT_ORIENTATION,      Property::BOOLEAN     },
   { "inheritScale",             Actor::Property::INHERIT_SCALE,            Property::BOOLEAN     },
   { "colorMode",                Actor::Property::COLOR_MODE,               Property::STRING      },
-  { "positionInheritance",      Actor::Property::POSITION_INHERITANCE,     Property::STRING      },
   { "drawMode",                 Actor::Property::DRAW_MODE,                Property::STRING      },
   { "sizeModeFactor",           Actor::Property::SIZE_MODE_FACTOR,         Property::VECTOR3     },
   { "widthResizePolicy",        Actor::Property::WIDTH_RESIZE_POLICY,      Property::STRING      },
@@ -3259,6 +3284,7 @@ const PropertyStringIndex PROPERTY_TABLE[] =
   { "inheritPosition",          Actor::Property::INHERIT_POSITION,         Property::BOOLEAN     },
   { "clippingMode",             Actor::Property::CLIPPING_MODE,            Property::STRING      },
   { "opacity",                  DevelActor::Property::OPACITY,             Property::FLOAT       },
+  { "updateSizeHint",           DevelActor::Property::UPDATE_SIZE_HINT,    Property::VECTOR2     },
 };
 const unsigned int PROPERTY_TABLE_COUNT = sizeof( PROPERTY_TABLE ) / sizeof( PROPERTY_TABLE[0] );
 } // unnamed namespace
@@ -3764,31 +3790,6 @@ int UtcDaliActorColorModePropertyAsString(void)
   END_TEST;
 }
 
-int UtcDaliActorPositionInheritancePropertyAsString(void)
-{
-  TestApplication application;
-
-  Actor actor = Actor::New();
-
-  actor.SetProperty( Actor::Property::POSITION_INHERITANCE, "INHERIT_PARENT_POSITION" );
-  DALI_TEST_EQUALS( actor.GetPositionInheritanceMode(), INHERIT_PARENT_POSITION, TEST_LOCATION );
-
-  actor.SetProperty( Actor::Property::POSITION_INHERITANCE, "USE_PARENT_POSITION" );
-  DALI_TEST_EQUALS( actor.GetPositionInheritanceMode(), USE_PARENT_POSITION, TEST_LOCATION );
-
-  actor.SetProperty( Actor::Property::POSITION_INHERITANCE, "USE_PARENT_POSITION_PLUS_LOCAL_POSITION" );
-  DALI_TEST_EQUALS( actor.GetPositionInheritanceMode(), USE_PARENT_POSITION_PLUS_LOCAL_POSITION, TEST_LOCATION );
-
-  actor.SetProperty( Actor::Property::POSITION_INHERITANCE, "DONT_INHERIT_POSITION" );
-  DALI_TEST_EQUALS( actor.GetPositionInheritanceMode(), DONT_INHERIT_POSITION, TEST_LOCATION );
-
-  // Invalid should not change anything
-  actor.SetProperty( Actor::Property::POSITION_INHERITANCE, "INVALID_ARG" );
-  DALI_TEST_EQUALS( actor.GetPositionInheritanceMode(), DONT_INHERIT_POSITION, TEST_LOCATION );
-
-  END_TEST;
-}
-
 int UtcDaliActorDrawModePropertyAsString(void)
 {
   TestApplication application;
@@ -3801,12 +3802,9 @@ int UtcDaliActorDrawModePropertyAsString(void)
   actor.SetProperty( Actor::Property::DRAW_MODE, "OVERLAY_2D" );
   DALI_TEST_EQUALS( actor.GetDrawMode(), DrawMode::OVERLAY_2D, TEST_LOCATION );
 
-  actor.SetProperty( Actor::Property::DRAW_MODE, "STENCIL" );
-  DALI_TEST_EQUALS( actor.GetDrawMode(), DrawMode::STENCIL, TEST_LOCATION );
-
   // Invalid should not change anything
   actor.SetProperty( Actor::Property::DRAW_MODE, "INVALID_ARG" );
-  DALI_TEST_EQUALS( actor.GetDrawMode(), DrawMode::STENCIL, TEST_LOCATION );
+  DALI_TEST_EQUALS( actor.GetDrawMode(), DrawMode::OVERLAY_2D, TEST_LOCATION );
 
   END_TEST;
 }
@@ -3832,27 +3830,6 @@ int UtcDaliActorColorModePropertyAsEnum(void)
   END_TEST;
 }
 
-int UtcDaliActorPositionInheritancePropertyAsEnum(void)
-{
-  TestApplication application;
-
-  Actor actor = Actor::New();
-
-  actor.SetProperty( Actor::Property::POSITION_INHERITANCE, INHERIT_PARENT_POSITION );
-  DALI_TEST_EQUALS( actor.GetPositionInheritanceMode(), INHERIT_PARENT_POSITION, TEST_LOCATION );
-
-  actor.SetProperty( Actor::Property::POSITION_INHERITANCE, USE_PARENT_POSITION );
-  DALI_TEST_EQUALS( actor.GetPositionInheritanceMode(), USE_PARENT_POSITION, TEST_LOCATION );
-
-  actor.SetProperty( Actor::Property::POSITION_INHERITANCE, USE_PARENT_POSITION_PLUS_LOCAL_POSITION );
-  DALI_TEST_EQUALS( actor.GetPositionInheritanceMode(), USE_PARENT_POSITION_PLUS_LOCAL_POSITION, TEST_LOCATION );
-
-  actor.SetProperty( Actor::Property::POSITION_INHERITANCE, DONT_INHERIT_POSITION );
-  DALI_TEST_EQUALS( actor.GetPositionInheritanceMode(), DONT_INHERIT_POSITION, TEST_LOCATION );
-
-  END_TEST;
-}
-
 int UtcDaliActorDrawModePropertyAsEnum(void)
 {
   TestApplication application;
@@ -3865,9 +3842,6 @@ int UtcDaliActorDrawModePropertyAsEnum(void)
   actor.SetProperty( Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D );
   DALI_TEST_EQUALS( actor.GetDrawMode(), DrawMode::OVERLAY_2D, TEST_LOCATION );
 
-  actor.SetProperty( Actor::Property::DRAW_MODE, DrawMode::STENCIL );
-  DALI_TEST_EQUALS( actor.GetDrawMode(), DrawMode::STENCIL, TEST_LOCATION );
-
   END_TEST;
 }
 
@@ -7175,3 +7149,134 @@ int UtcDaliChildMovedSignalP(void)
 
   END_TEST;
 }
+
+int utcDaliActorCulled(void)
+{
+  TestApplication application;
+  auto stage = Stage::GetCurrent();
+
+  tet_infoline( "Check that the actor is culled if the actor is out of the screen" );
+
+  Actor actor = Actor::New();
+  actor.SetSize( 10.0f, 10.0f );
+
+  Geometry geometry = CreateQuadGeometry();
+  Shader shader = CreateShader();
+  Renderer renderer = Renderer::New(geometry, shader);
+  actor.AddRenderer( renderer );
+
+  stage.Add( actor );
+
+  application.SendNotification();
+  application.Render( 0 );
+
+  DALI_TEST_EQUALS( actor.GetProperty< bool >( DevelActor::Property::CULLED ), false, TEST_LOCATION );
+
+  PropertyNotification notification = actor.AddPropertyNotification( DevelActor::Property::CULLED, LessThanCondition( 0.5f ) );
+  notification.SetNotifyMode( PropertyNotification::NotifyOnChanged );
+
+  // Connect NotifySignal
+  bool propertyNotificationSignal( false );
+  PropertyNotification source;
+  CulledPropertyNotificationFunctor f( propertyNotificationSignal, source );
+  notification.NotifySignal().Connect( &application, f ) ;
+
+  actor.SetPosition( 1000.0f, 1000.0f );
+
+  application.SendNotification();
+  application.Render();
+
+  application.SendNotification();
+
+  DALI_TEST_EQUALS( actor.GetProperty< bool >( DevelActor::Property::CULLED ), true, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( propertyNotificationSignal, true, TEST_LOCATION );
+  DALI_TEST_EQUALS( source.GetTargetProperty(), static_cast< int >( DevelActor::Property::CULLED ), TEST_LOCATION );
+  DALI_TEST_EQUALS( source.GetTarget().GetProperty< bool >( source.GetTargetProperty() ), true, TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliActorUpdateSizeHint(void)
+{
+  TestApplication application;
+
+  Actor actor = Actor::New();
+  Vector3 vector(100.0f, 100.0f, 0.0f);
+
+  DALI_TEST_CHECK(vector != actor.GetCurrentSize());
+
+  actor.SetSize(vector.x, vector.y);
+
+
+  Vector2 updateSizeHint = Vector2(150.f, 150.f);
+  actor.SetProperty(Dali::DevelActor::Property::UPDATE_SIZE_HINT, updateSizeHint);
+
+  // Flush the queue and render once
+  application.SendNotification();
+  application.Render();
+
+
+  Vector2 currentSizeHint = actor.GetProperty( Dali::DevelActor::Property::UPDATE_SIZE_HINT ).Get< Vector2 >();
+  DALI_TEST_EQUALS( currentSizeHint, updateSizeHint, Math::MACHINE_EPSILON_0, TEST_LOCATION );
+
+  // Flush the queue and render once
+  application.SendNotification();
+  application.Render();
+
+  END_TEST;
+}
+
+int utcDaliEnsureRenderWhenRemovingLastRenderableActor(void)
+{
+  TestApplication application;
+  auto stage = Stage::GetCurrent();
+
+  tet_infoline( "Ensure we clear the screen when the last actor is removed" );
+
+  Actor actor = CreateRenderableActor();
+  actor.SetSize( 100.0f, 100.0f );
+  stage.Add( actor );
+
+  application.SendNotification();
+  application.Render();
+
+  auto& glAbstraction = application.GetGlAbstraction();
+  const auto clearCountBefore = glAbstraction.GetClearCountCalled();
+
+  actor.Unparent();
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 1, TEST_LOCATION );
+
+  END_TEST;
+}
+
+int utcDaliEnsureRenderWhenMakingLastActorInvisible(void)
+{
+  TestApplication application;
+  auto stage = Stage::GetCurrent();
+
+  tet_infoline( "Ensure we clear the screen when the last actor is made invisible" );
+
+  Actor actor = CreateRenderableActor();
+  actor.SetSize( 100.0f, 100.0f );
+  stage.Add( actor );
+
+  application.SendNotification();
+  application.Render();
+
+  auto& glAbstraction = application.GetGlAbstraction();
+  const auto clearCountBefore = glAbstraction.GetClearCountCalled();
+
+  actor.SetVisible( false );
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( glAbstraction.GetClearCountCalled(), clearCountBefore + 1, TEST_LOCATION );
+
+  END_TEST;
+}