예제 #1
0
int UtcDaliRenderTaskListGetTask(void)
{
  TestApplication application;

  tet_infoline("Testing RenderTaskList::GetTask()");

  RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
  RenderTask defaultTask = taskList.GetTask( 0u );
  DALI_TEST_CHECK( 1u == taskList.GetTaskCount() );
  DALI_TEST_CHECK( defaultTask );
  DALI_TEST_CHECK( defaultTask == taskList.GetTask( 0u ) );

  RenderTask newTask = taskList.CreateTask();
  DALI_TEST_CHECK( 2u == taskList.GetTaskCount() );

  RenderTask temp = taskList.GetTask( 0u );
  RenderTask temp2 = taskList.GetTask( 1u );

  DALI_TEST_CHECK( newTask );
  DALI_TEST_CHECK( defaultTask != newTask );
  DALI_TEST_CHECK( taskList.GetTask( 0u ) == defaultTask );
  DALI_TEST_CHECK( taskList.GetTask( 1u ) == newTask );
  DALI_TEST_CHECK( taskList.GetTask( 1u ) != defaultTask );

  taskList.RemoveTask( taskList.GetTask(0u) );
  DALI_TEST_CHECK( 1u == taskList.GetTaskCount() );
  DALI_TEST_CHECK( taskList.GetTask( 0u ) != defaultTask  );
  DALI_TEST_CHECK( taskList.GetTask( 0u ) == newTask );
  END_TEST;
}
예제 #2
0
int UtcDaliImageActorUseImageAlpha04(void)
{
  TestApplication application;

  tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");

  FrameBufferImage image = FrameBufferImage::New( 100, 50, Pixel::RGBA8888 );
  RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
  RenderTask task = taskList.GetTask( 0u );
  task.SetTargetFrameBuffer( image ); // To ensure frame buffer is connected
  application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
  application.SendNotification();
  application.Render(0);

  ImageActor actor = ImageActor::New( image );
  application.SendNotification();
  application.Render(0);

  actor.SetBlendMode( BlendingMode::ON );
  actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0));
  actor.SetSize(100, 50);
  application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
  Stage::GetCurrent().Add(actor);

  application.SendNotification();
  application.Render();

  const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
  DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
  DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
  END_TEST;
}
int UtcDaliHitTestAlgorithmOrtho02(void)
{
  TestApplication application;
  tet_infoline("Testing Dali::HitTestAlgorithm with offset Ortho camera()");

  Stage stage = Stage::GetCurrent();
  RenderTaskList renderTaskList = stage.GetRenderTaskList();
  RenderTask defaultRenderTask = renderTaskList.GetTask(0u);
  Dali::CameraActor cameraActor = defaultRenderTask.GetCameraActor();

  Vector2 stageSize ( stage.GetSize() );
  cameraActor.SetOrthographicProjection(-stageSize.x * 0.3f,  stageSize.x * 0.7f,
                                         stageSize.y * 0.3f, -stageSize.y * 0.7f,
                                         800.0f, 4895.0f);
  cameraActor.SetPosition(0.0f, 0.0f, 1600.0f);

  Vector2 actorSize( stageSize * 0.5f );
  // Create two actors with half the size of the stage and set them to be partially overlapping
  Actor blue = Actor::New();
  blue.SetName( "Blue" );
  blue.SetAnchorPoint( AnchorPoint::TOP_LEFT );
  blue.SetParentOrigin( Vector3(0.2f, 0.2f, 0.5f) );
  blue.SetSize( actorSize );
  blue.SetZ(30.0f);

  Actor green = Actor::New( );
  green.SetName( "Green" );
  green.SetAnchorPoint( AnchorPoint::TOP_LEFT );
  green.SetParentOrigin( Vector3(0.4f, 0.4f, 0.5f) );
  green.SetSize( actorSize );

  // Add the actors to the view
  stage.Add( blue );
  stage.Add( green );

  // Render and notify
  application.SendNotification();
  application.Render(0);
  application.Render(10);

  HitTestAlgorithm::Results results;
  HitTest(stage, Vector2( 240.0f, 400.0f ), results, &DefaultIsActorTouchableFunction);
  DALI_TEST_CHECK( results.actor == green );
  DALI_TEST_EQUALS( results.actorCoordinates, actorSize * 0.6f, TEST_LOCATION );

  HitTest(stage, Vector2::ZERO, results, &DefaultIsActorTouchableFunction);
  DALI_TEST_CHECK( results.actor == blue );
  DALI_TEST_EQUALS( results.actorCoordinates, Vector2::ZERO, TEST_LOCATION );

  HitTest(stage, stageSize, results, &DefaultIsActorTouchableFunction);
  DALI_TEST_CHECK( ! results.actor );
  DALI_TEST_EQUALS( results.actorCoordinates, Vector2::ZERO, TEST_LOCATION );

  // Just inside green
  HitTest(stage, stageSize*0.69f, results, &DefaultIsActorTouchableFunction);
  DALI_TEST_CHECK( results.actor == green );
  DALI_TEST_EQUALS( results.actorCoordinates, actorSize * 0.98f, TEST_LOCATION );
  END_TEST;
}
예제 #4
0
int UtcDaliRenderTaskListGetTaskCount(void)
{
  TestApplication application;

  tet_infoline("Testing RenderTaskList::GetTaskCount()");

  RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
  DALI_TEST_CHECK( 1u == taskList.GetTaskCount() );

  taskList.RemoveTask( taskList.GetTask(0u) );
  DALI_TEST_CHECK( 0u == taskList.GetTaskCount() );
  END_TEST;
}
예제 #5
0
void Magnifier::Initialize()
{
  Actor self = Self();
  mPropertySourcePosition = self.RegisterProperty( Toolkit::Magnifier::SOURCE_POSITION_PROPERTY_NAME, Vector3::ZERO );
  Vector2 stageSize(Stage::GetCurrent().GetSize());

  Layer dummyLayer = Layer::New();
  Stage().GetCurrent().Add(dummyLayer);
  dummyLayer.SetParentOrigin(ParentOrigin::CENTER);

  // NOTE:
  // sourceActor is a dummy delegate actor that takes the source property position,
  // and generates a WORLD_POSITION, which is 1 frame behind the source property.
  // This way the constraints for determining the camera position (source) and those
  // for determining viewport position use the same 1 frame old values.
  // A simple i) CameraPos = f(B), ii) B = f(A) set of constraints wont suffice as
  // although CameraPos will use B, which is A's previous value. The constraint will
  // not realise that B is still dirty as far as constraint (i) is concerned.
  // Perhaps this is a bug in the way the constraint system factors into what is dirty
  // and what is not.
  mSourceActor = Actor::New();
  dummyLayer.Add(mSourceActor);
  mSourceActor.SetParentOrigin(ParentOrigin::CENTER);
  Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
                                                    Source( self, mPropertySourcePosition ),
                                                    EqualToConstraint() );
  mSourceActor.ApplyConstraint(constraint);

  // create the render task this will render content on top of everything
  // based on camera source position.
  InitializeRenderTask();

  // set up some constraints to:
  // i) reposition (dest) frame actor based on magnifier actor's world position (this is 1 frame delayed)
  // ii) reposition and resize (dest) the render task's viewport based on magnifier actor's world position (1 frame delayed) & size.
  // iii) reposition (source) camera actor based on magnifier source actor's world position (this is 1 frame delayed)

  // Apply constraint to camera's position
  // Position our camera at the same distance from its target as the default camera is.
  // The camera position doesn't affect how we render, just what we render (due to near and far clip planes)
  // NOTE: We can't interrogate the default camera's position as it is not known initially (takes 1 frame
  // for value to update).
  // But we can determine the initial position using the same formula:
  // distance = stage.height * 0.5 / tan(FOV * 0.5)

  RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
  RenderTask renderTask = taskList.GetTask(0u);
  float fov = renderTask.GetCameraActor().GetFieldOfView();
  mDefaultCameraDistance = (stageSize.height * 0.5f) / tanf(fov * 0.5f);

  // Use a 1 frame delayed source position to determine the camera actor's position.
  // This is necessary as the viewport is determined by the Magnifier's Actor's World position (which is computed
  // at the end of the update cycle i.e. after constraints have been applied.)
  //Property::Index propertySourcePositionDelayed = mCameraActor.RegisterProperty("delayed-source-position", Vector3::ZERO);

  constraint = Constraint::New<Vector3>( Actor::POSITION,
                                                    Source( mSourceActor, Actor::WORLD_POSITION ),
                                                    CameraActorPositionConstraint(stageSize, mDefaultCameraDistance) );
  mCameraActor.ApplyConstraint(constraint);

  // Apply constraint to render-task viewport position
  constraint = Constraint::New<Vector2>( RenderTask::VIEWPORT_POSITION,
                                         Source( self, Actor::WORLD_POSITION ),//mPropertySourcePosition ),
                                         Source( self, Actor::SIZE ),
                                         Source( self, Actor::WORLD_SCALE),
                                         RenderTaskViewportPositionConstraint(stageSize) );
  mTask.ApplyConstraint(constraint);

  // Apply constraint to render-task viewport position
  constraint = Constraint::New<Vector2>( RenderTask::VIEWPORT_SIZE,
                                         Source( self, Actor::SIZE ),
                                         Source( self, Actor::WORLD_SCALE),
                                         RenderTaskViewportSizeConstraint() );
  mTask.ApplyConstraint(constraint);
}
int UtcDaliHitTestAlgorithmWithFunctorOnRenderTask(void)
{
  TestApplication application;
  tet_infoline("Testing Dali::HitTestAlgorithm functor, specific to a given render task");

  Stage stage = Stage::GetCurrent();
  Size stageSize = stage.GetSize();
  RenderTaskList taskList = stage.GetRenderTaskList();

  Actor actor[2];

  for( int i=0; i<2; i++ )
  {
    actor[i] = Actor::New();
    actor[i].SetSize(100.f, 100.f);
    actor[i].SetParentOrigin(ParentOrigin::TOP_LEFT);
    actor[i].SetAnchorPoint(AnchorPoint::TOP_LEFT);
    actor[i].SetName("HittableActor");
    stage.Add(actor[i]);
  }
  Vector2 position( 50.f, 40.f );
  actor[1].SetPosition( position.x, position.y );

  RenderTask renderTask[2];
  renderTask[0] = taskList.GetTask( 0u );

  FrameBufferImage frameBufferImage =  FrameBufferImage::New(stageSize.width, stageSize.height, Pixel::A8, Image::Never);
  renderTask[1] = taskList.CreateTask();
  renderTask[1].SetSourceActor( actor[1] );
  renderTask[1].SetExclusive( true );
  renderTask[1].SetInputEnabled( true );
  renderTask[1].SetTargetFrameBuffer( frameBufferImage );
  renderTask[1].SetRefreshRate( RenderTask::REFRESH_ONCE );
  renderTask[1].SetScreenToFrameBufferFunction( RenderTask::FULLSCREEN_FRAMEBUFFER_FUNCTION );

  // Render and notify
  application.SendNotification();
  application.Render();
  application.Render();
  application.SendNotification();

  // Perform a hit-test at the given screen coordinates with different render tasks

  Dali::HitTestAlgorithm::Results results;
  Vector2 screenCoordinates( 25.f, 25.f );

  Dali::HitTestAlgorithm::HitTest( renderTask[0], screenCoordinates, results, IsActorHittableFunction );
  DALI_TEST_CHECK( results.actor == actor[0] );
  DALI_TEST_EQUALS( screenCoordinates, results.actorCoordinates, 0.1f, TEST_LOCATION );

  results.actor = Actor();
  results.actorCoordinates = Vector2::ZERO;
  Dali::HitTestAlgorithm::HitTest( renderTask[1], screenCoordinates, results, IsActorHittableFunction );
  DALI_TEST_CHECK( !results.actor );
  DALI_TEST_EQUALS( Vector2::ZERO, results.actorCoordinates, 0.1f, TEST_LOCATION );

  screenCoordinates.x = 80.f;
  screenCoordinates.y = 70.f;

  results.actor = Actor();
  results.actorCoordinates = Vector2::ZERO;
  Dali::HitTestAlgorithm::HitTest( renderTask[0], screenCoordinates, results, IsActorHittableFunction );
  DALI_TEST_CHECK( results.actor == actor[0] );
  DALI_TEST_EQUALS( screenCoordinates, results.actorCoordinates, 0.1f, TEST_LOCATION );

  results.actor = Actor();
  results.actorCoordinates = Vector2::ZERO;
  Dali::HitTestAlgorithm::HitTest( renderTask[1], screenCoordinates, results, IsActorHittableFunction );
  DALI_TEST_CHECK( results.actor == actor[1]);
  DALI_TEST_EQUALS( screenCoordinates - position, results.actorCoordinates, 0.1f, TEST_LOCATION );


  screenCoordinates.x = 120.f;
  screenCoordinates.y = 130.f;

  results.actor = Actor();
  results.actorCoordinates = Vector2::ZERO;
  Dali::HitTestAlgorithm::HitTest( renderTask[0], screenCoordinates, results, IsActorHittableFunction );
  DALI_TEST_CHECK( results.actor == actor[1] );
  DALI_TEST_EQUALS( screenCoordinates - position, results.actorCoordinates, 0.1f, TEST_LOCATION );

  results.actor = Actor();
  results.actorCoordinates = Vector2::ZERO;
  Dali::HitTestAlgorithm::HitTest( renderTask[1], screenCoordinates, results, IsActorHittableFunction );
  DALI_TEST_CHECK( results.actor == actor[1]);
  DALI_TEST_EQUALS( screenCoordinates - position, results.actorCoordinates, 0.1f, TEST_LOCATION );
  END_TEST;
}
int UtcDaliHoverOutsideCameraNearFarPlanes(void)
{
  TestApplication application;

  Stage stage = Stage::GetCurrent();
  Vector2 stageSize = stage.GetSize();

  Actor actor = Actor::New();
  actor.SetSize(100.0f, 100.0f);
  actor.SetAnchorPoint(AnchorPoint::CENTER);
  actor.SetParentOrigin(ParentOrigin::CENTER);
  stage.Add(actor);

  // Render and notify
  application.SendNotification();
  application.Render();

  // Get the camera's near and far planes
  RenderTaskList taskList = stage.GetRenderTaskList();
  Dali::RenderTask task = taskList.GetTask(0);
  CameraActor camera = task.GetCameraActor();
  float nearPlane = camera.GetNearClippingPlane();
  float farPlane = camera.GetFarClippingPlane();

  // Calculate the current distance of the actor from the camera
  float tanHalfFov = tanf(camera.GetFieldOfView() * 0.5f);
  float distance = (stageSize.y * 0.5f) / tanHalfFov;

  // Connect to actor's hovered signal
  SignalData data;
  HoverEventFunctor functor( data );
  actor.HoveredSignal().Connect( &application, functor );

  Vector2 screenCoordinates( stageSize.x * 0.5f, stageSize.y * 0.5f );

  // Emit a started signal
  application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
  DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
  data.Reset();

  // Emit a started signal where actor is just at the camera's near plane
  actor.SetZ(distance - nearPlane);

  // Render and notify
  application.SendNotification();
  application.Render();

  application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
  DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
  data.Reset();

  // Emit a started signal where actor is closer than the camera's near plane
  actor.SetZ((distance - nearPlane) + 1.0f);

  // Render and notify
  application.SendNotification();
  application.Render();

  application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
  DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
  data.Reset();

  // Emit a started signal where actor is just at the camera's far plane
  actor.SetZ(distance - farPlane);

  // Render and notify
  application.SendNotification();
  application.Render();

  application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
  DALI_TEST_EQUALS( true, data.functorCalled, TEST_LOCATION );
  data.Reset();

  // Emit a started signal where actor is further than the camera's far plane
  actor.SetZ((distance - farPlane) - 1.0f);

  // Render and notify
  application.SendNotification();
  application.Render();

  application.ProcessEvent( GenerateSingleHover( TouchPoint::Started, screenCoordinates ) );
  DALI_TEST_EQUALS( false, data.functorCalled, TEST_LOCATION );
  data.Reset();
  END_TEST;
}