// Different requests, incompatible resource, so two loads result:
int UtcDaliImageFactoryInCompatibleResource(void)
{
  TestApplication application;
  tet_infoline( "UtcDaliImageFactoryCompatibleResource02 - Two requests mapping to same resource." );

  ImageFactory& imageFactory  = Internal::ThreadLocalStorage::Get().GetImageFactory();

  Vector2 testSize(2048.0f, 2048.0f);
  application.GetPlatform().SetClosestImageSize(testSize);

  // request with default attributes ( size is 0,0 )
  RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL );
  ResourceTicketPtr ticket = imageFactory.Load( *req.Get() );

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

  // emulate load success
  EmulateImageLoaded( application, testSize.x, testSize.y );

  // Request substantially different size than actual image.
  // This will issue a second resource load as difference in sizes is greater than
  // the small fudge factor used in the ImageFactory cache.
  ImageAttributes attr = ImageAttributes::New();
  attr.SetSize( testSize.x - 16, testSize.y - 16 );
  RequestPtr req2 = imageFactory.RegisterRequest( gTestImageFilename, &attr );
  ResourceTicketPtr ticket2 = imageFactory.Load( *req2.Get() );

  DALI_TEST_CHECK( req != req2 ); // different requests
  DALI_TEST_CHECK( ticket->GetId() != ticket2->GetId() ); // differnet resources
  END_TEST;
}
// Different requests, compatible resource
int UtcDaliImageFactoryCompatibleResource03(void)
{
  TestApplication application;
  tet_infoline( "UtcDaliImageFactoryCompatibleResource03 - Two requests mapping to same resource" );

  ImageFactory& imageFactory  = Internal::ThreadLocalStorage::Get().GetImageFactory();

  Vector2 testSize(80.0f, 80.0f);
  application.GetPlatform().SetClosestImageSize(testSize);

  // this time use defined attributes, nut just NULL
  ImageAttributes attr = ImageAttributes::New();
  attr.SetSize( 120, 120 );

  // request with default attributes ( size is 0,0 )
  RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, &attr );
  ResourceTicketPtr ticket = imageFactory.Load( *req.Get() );

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

  // emulate load success
  EmulateImageLoaded( application, 80, 80 );

  ImageAttributes attr2 = ImageAttributes::New();
  attr2.SetSize( 80, 80 );
  RequestPtr req2 = imageFactory.RegisterRequest( gTestImageFilename, &attr2 );
  ResourceTicketPtr ticket2 = imageFactory.Load( *req2.Get() );

  DALI_TEST_CHECK( req != req2 ); // different requests
  DALI_TEST_EQUALS( ticket->GetId(), ticket2->GetId(), TEST_LOCATION ); // same resource
  END_TEST;
}
// Different requests, compatible resource
int UtcDaliImageFactoryCompatibleResource02(void)
{
  TestApplication application;
  tet_infoline( "UtcDaliImageFactoryCompatibleResource02 - Two requests mapping to same resource." );

  ImageFactory& imageFactory  = Internal::ThreadLocalStorage::Get().GetImageFactory();

  Vector2 testSize( 2048.0f, 2048.0f );
  application.GetPlatform().SetClosestImageSize( testSize );

  // request with default attributes ( size is 0,0 )
  RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL );
  ResourceTicketPtr ticket = imageFactory.Load( *req.Get() );

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

  // emulate load success
  EmulateImageLoaded( application, testSize.x, testSize.y );

  // Request slightly bigger size than actual image.
  // This will load the same resource as the ImageFactory cache uses a small fudge factor in matching.
  // See UtcDaliImageFactoryReload06
  ImageAttributes attr = ImageAttributes::New();
  attr.SetSize( testSize.x + 1, testSize.y + 1 );
  RequestPtr req2 = imageFactory.RegisterRequest( gTestImageFilename, &attr );
  ResourceTicketPtr ticket2 = imageFactory.Load( *req2.Get() );

  DALI_TEST_CHECK( req != req2 ); // different requests
  DALI_TEST_EQUALS( ticket->GetId(), ticket2->GetId(), TEST_LOCATION ); // same resource
  END_TEST;
}
// Initally two different requests map to same resource.
// After overwriting the file, they load different image resources.
int UtcDaliImageFactoryReload06(void)
{
  TestApplication application;
  tet_infoline( "UtcDaliImageFactoryReload06 - Two requests first mapping to same resource, then different resources." );

  ImageFactory& imageFactory  = Internal::ThreadLocalStorage::Get().GetImageFactory();

  Vector2 testSize(2048.0f, 2048.0f);
    application.GetPlatform().SetClosestImageSize( testSize );

  // request with default attributes ( size is 0,0 )
  RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL );
  ResourceTicketPtr ticket = imageFactory.Load( *req.Get() );

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

  // emulate load success
  EmulateImageLoaded( application, testSize.x, testSize.y );

  // Request bigger size than actual image.
  // This will load the same resource.
  // However if image size changes later on to eg. 512*512 (file is overwritten),
  // reissuing these two requests will load different resources.
  ImageAttributes attr = ImageAttributes::New();
  attr.SetSize( testSize.x + 1, testSize.y + 1 );
  RequestPtr req2 = imageFactory.RegisterRequest( gTestImageFilename, &attr );
  ResourceTicketPtr ticket2 = imageFactory.Load( *req2.Get() );

  DALI_TEST_CHECK( req != req2 ); // different requests
  DALI_TEST_EQUALS( ticket->GetId(), ticket2->GetId(), TEST_LOCATION ); // same resource

  Vector2 newSize(512.0f, 512.0f);
  application.GetPlatform().SetClosestImageSize(newSize);

  // reload fixed size (192,192) request
  ticket2 = imageFactory.Reload( *req2.Get() );

  // emulate load success
  // note: this is the only way to emulate what size is loaded by platform abstraction
  EmulateImageLoaded( application, testSize.x + 1, testSize.y + 1 );

  // reload default size request
  ticket = imageFactory.Reload( *req.Get() );

  DALI_TEST_CHECK( ticket->GetId() != ticket2->GetId() ); // different resources
  END_TEST;
}
Пример #5
0
ResourceTicketPtr ModelFactory::Load( const std::string& filename )
{
  ResourceTicketPtr ticket;
  ModelResourceType modelResourceType; // construct first as no copy ctor (needed to bind ref to object)
  ResourceTypePath typePath(modelResourceType, filename);

  // Search for a matching resource
  ResourceTypePathIdIter iter = mResourceTypePathIdMap.end();
  if ( !mResourceTypePathIdMap.empty() )
  {
    iter = mResourceTypePathIdMap.find( typePath );
  }

  if ( mResourceTypePathIdMap.end() != iter )
  {
    // The resource was previously requested
    unsigned int resourceId = iter->second;

    // The resource may still be alive; share the ticket
    ticket = mResourceClient.RequestResourceTicket( resourceId );

    // Clean-up the map of resource IDs, if the ticket has been discarded
    if ( !ticket )
    {
      mResourceTypePathIdMap.erase( iter );
    }
  }

  // Request a new model resource, if necessary
  if ( !ticket )
  {
    ModelResourceType modelResourceType; // construct first as no copy ctor (needed to bind ref to object)
    ticket = mResourceClient.RequestResource(modelResourceType, filename);

    mResourceTypePathIdMap.insert( ResourceTypePathIdPair( typePath, ticket->GetId() ) );
  }

  return ticket;
}