ImageFactory& imageFactory = Internal::ThreadLocalStorage::Get().GetImageFactory();
RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL );
- ResourceTicketPtr ticket = imageFactory.Load( req.Get() );
+ ResourceTicketPtr ticket = imageFactory.Load( *req.Get() );
RequestPtr req2 = imageFactory.RegisterRequest( gTestImageFilename, NULL );
- ResourceTicketPtr ticket2 = imageFactory.Load( req2.Get() );
+ ResourceTicketPtr ticket2 = imageFactory.Load( *req2.Get() );
DALI_TEST_EQUALS( req, req2, TEST_LOCATION );
DALI_TEST_EQUALS( ticket, ticket2, TEST_LOCATION );
req2 = imageFactory.RegisterRequest( gTestImageFilename, NULL );
- ResourceTicketPtr ticket3 = imageFactory.Load( req2.Get() );
+ ResourceTicketPtr ticket3 = imageFactory.Load( *req2.Get() );
DALI_TEST_EQUALS( req, req2, TEST_LOCATION );
DALI_TEST_EQUALS( ticket, ticket3, TEST_LOCATION );
// request differs in scaled size - not default size
ImageAttributes attr = ImageAttributes::New( 80, 160, Pixel::BGR8888 );
req2 = imageFactory.RegisterRequest( gTestImageFilename, &attr );
- ResourceTicketPtr ticket4 = imageFactory.Load( req2.Get() );
+ ResourceTicketPtr ticket4 = imageFactory.Load( *req2.Get() );
DALI_TEST_CHECK( req != req2 );
END_TEST;
}
// request with default attributes ( size is 0,0 )
RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL );
- ResourceTicketPtr ticket = imageFactory.Load( req.Get() );
+ ResourceTicketPtr ticket = imageFactory.Load( *req.Get() );
application.SendNotification();
application.Render();
ImageAttributes attr = ImageAttributes::New();
attr.SetSize( 80, 80 );
RequestPtr req2 = imageFactory.RegisterRequest( gTestImageFilename, &attr );
- ResourceTicketPtr ticket2 = imageFactory.Load( req2.Get() );
+ ResourceTicketPtr ticket2 = imageFactory.Load( *req2.Get() );
DALI_TEST_CHECK( req != req2 ); // different requests
DALI_TEST_EQUALS( ticket->GetId(), ticket2->GetId(), TEST_LOCATION ); // same resource
// request with default attributes ( size is 0,0 )
RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL );
- ResourceTicketPtr ticket = imageFactory.Load( req.Get() );
+ ResourceTicketPtr ticket = imageFactory.Load( *req.Get() );
application.SendNotification();
application.Render();
ImageAttributes attr = ImageAttributes::New();
attr.SetSize( 92, 92 );
RequestPtr req2 = imageFactory.RegisterRequest( gTestImageFilename, &attr );
- ResourceTicketPtr ticket2 = imageFactory.Load( req2.Get() );
+ ResourceTicketPtr ticket2 = imageFactory.Load( *req2.Get() );
DALI_TEST_CHECK( req != req2 ); // different requests
DALI_TEST_EQUALS( ticket->GetId(), ticket2->GetId(), TEST_LOCATION ); // same resource
// request with default attributes ( size is 0,0 )
RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, &attr );
- ResourceTicketPtr ticket = imageFactory.Load( req.Get() );
+ ResourceTicketPtr ticket = imageFactory.Load( *req.Get() );
application.SendNotification();
application.Render();
ImageAttributes attr2 = ImageAttributes::New();
attr2.SetSize( 80, 80 );
RequestPtr req2 = imageFactory.RegisterRequest( gTestImageFilename, &attr2 );
- ResourceTicketPtr ticket2 = imageFactory.Load( req2.Get() );
+ ResourceTicketPtr ticket2 = imageFactory.Load( *req2.Get() );
DALI_TEST_CHECK( req != req2 ); // different requests
DALI_TEST_EQUALS( ticket->GetId(), ticket2->GetId(), TEST_LOCATION ); // same resource
ImageFactory& imageFactory = Internal::ThreadLocalStorage::Get().GetImageFactory();
RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL );
- ResourceTicketPtr ticket = imageFactory.Load( req.Get() );
+ ResourceTicketPtr ticket = imageFactory.Load( *req.Get() );
- ResourceTicketPtr ticket2 = imageFactory.Reload( req.Get() );
+ ResourceTicketPtr ticket2 = imageFactory.Reload( *req.Get() );
DALI_TEST_EQUALS( ticket, ticket2, TEST_LOCATION );
- ResourceTicketPtr ticket3 = imageFactory.Reload( req.Get() );
+ ResourceTicketPtr ticket3 = imageFactory.Reload( *req.Get() );
DALI_TEST_EQUALS( ticket, ticket3, TEST_LOCATION );
END_TEST;
}
application.GetPlatform().SetClosestImageSize(testSize);
RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL );
- ResourceTicketPtr ticket = imageFactory.Load( req.Get() );
+ ResourceTicketPtr ticket = imageFactory.Load( *req.Get() );
application.SendNotification();
application.Render();
DALI_TEST_CHECK( application.GetPlatform().WasCalled( TestPlatformAbstraction::LoadResourceFunc ) );
application.GetPlatform().ResetTrace();
- ResourceTicketPtr ticket2 = imageFactory.Reload( req.Get() );
+ ResourceTicketPtr ticket2 = imageFactory.Reload( *req.Get() );
application.SendNotification();
application.Render();
// emulate load success
EmulateImageLoaded( application, 80, 80 );
- ResourceTicketPtr ticket3 = imageFactory.Reload( req.Get() );
+ ResourceTicketPtr ticket3 = imageFactory.Reload( *req.Get() );
application.SendNotification();
application.Render();
DALI_TEST_CHECK( application.GetPlatform().WasCalled( TestPlatformAbstraction::LoadResourceFunc ) );
application.GetPlatform().ResetTrace();
- ticket3 = imageFactory.Reload( req.Get() );
+ ticket3 = imageFactory.Reload( *req.Get() );
application.SendNotification();
application.Render();
application.GetPlatform().SetClosestImageSize( testSize );
RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL );
- ResourceTicketPtr ticket = imageFactory.Load( req.Get() );
+ ResourceTicketPtr ticket = imageFactory.Load( *req.Get() );
application.SendNotification();
application.Render();
application.GetPlatform().SetClosestImageSize( newSize );
// Image file changed size, new resource request should be issued
- ResourceTicketPtr ticket2 = imageFactory.Reload( req.Get() );
+ ResourceTicketPtr ticket2 = imageFactory.Reload( *req.Get() );
DALI_TEST_CHECK( ticket != ticket2 );
- ResourceTicketPtr ticket3 = imageFactory.Reload( req.Get() );
+ ResourceTicketPtr ticket3 = imageFactory.Reload( *req.Get() );
DALI_TEST_EQUALS( ticket2, ticket3, TEST_LOCATION );
END_TEST;
}
application.GetPlatform().SetClosestImageSize(testSize);
RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL );
- ResourceTicketPtr ticket = imageFactory.Load( req.Get() );
+ ResourceTicketPtr ticket = imageFactory.Load( *req.Get() );
application.SendNotification();
application.Render();
DALI_TEST_CHECK( application.GetPlatform().WasCalled( TestPlatformAbstraction::LoadResourceFunc ) );
application.GetPlatform().ResetTrace();
- ResourceTicketPtr ticket2 = imageFactory.Reload( req.Get() );
+ ResourceTicketPtr ticket2 = imageFactory.Reload( *req.Get() );
application.SendNotification();
application.Render();
// emulate load success
EmulateImageLoaded( application, 80, 80 );
- ResourceTicketPtr ticket3 = imageFactory.Reload( req.Get() );
+ ResourceTicketPtr ticket3 = imageFactory.Reload( *req.Get() );
application.SendNotification();
application.Render();
application.GetPlatform().ResetTrace();
// still loading
- ticket3 = imageFactory.Reload( req.Get() );
+ ticket3 = imageFactory.Reload( *req.Get() );
application.SendNotification();
application.Render();
application.SendNotification();
application.SendNotification();
application.Render();
- ResourceTicketPtr ticket = imageFactory.Reload( req.Get() );
+ ResourceTicketPtr ticket = imageFactory.Reload( *req.Get() );
DALI_TEST_CHECK( !application.GetPlatform().WasCalled( TestPlatformAbstraction::LoadResourceFunc ) );
DALI_TEST_CHECK( !ticket );
// this happens when Image is put on stage
- ticket = imageFactory.Load( req.Get() );
+ ticket = imageFactory.Load( *req.Get() );
application.SendNotification();
application.Render();
DALI_TEST_CHECK( ticket );
application.GetPlatform().ResetTrace();
- ticket = imageFactory.Reload( req.Get() );
+ ticket = imageFactory.Reload( *req.Get() );
application.SendNotification();
application.Render();
// emulate load success
EmulateImageLoaded( application, 80, 80 );
- ticket = imageFactory.Reload( req.Get() );
+ ticket = imageFactory.Reload( *req.Get() );
application.SendNotification();
application.Render();
// request with default attributes ( size is 0,0 )
RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL );
- ResourceTicketPtr ticket = imageFactory.Load( req.Get() );
+ ResourceTicketPtr ticket = imageFactory.Load( *req.Get() );
application.SendNotification();
application.Render();
ImageAttributes attr = ImageAttributes::New();
attr.SetSize( 92, 92 );
RequestPtr req2 = imageFactory.RegisterRequest( gTestImageFilename, &attr );
- ResourceTicketPtr ticket2 = imageFactory.Load( req2.Get() );
+ ResourceTicketPtr ticket2 = imageFactory.Load( *req2.Get() );
DALI_TEST_CHECK( req != req2 ); // different requests
DALI_TEST_EQUALS( ticket->GetId(), ticket2->GetId(), TEST_LOCATION ); // same resource
application.GetPlatform().SetClosestImageSize(newSize);
// reload fixed size (192,192) request
- ticket2 = imageFactory.Reload( req2.Get() );
+ 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, 92, 92 );
// reload default size request
- ticket = imageFactory.Reload( req.Get() );
+ ticket = imageFactory.Reload( *req.Get() );
DALI_TEST_CHECK( ticket->GetId() != ticket2->GetId() ); // different resources
END_TEST;
std::size_t urlHash = CalculateHash( filename );
Request* foundReq( NULL );
- foundReq = FindRequest(filename, urlHash, attr);
+ foundReq = FindRequest( filename, urlHash, attr );
if( !foundReq )
{
return foundReq;
}
-ResourceTicketPtr ImageFactory::Load( Request *req )
+ResourceTicketPtr ImageFactory::Load( Request& request )
{
ResourceTicketPtr ticket;
- DALI_ASSERT_DEBUG( req );
- ResourceId resId = req->resourceId;
+ const ResourceId resId = request.resourceId;
if( resId == 0 )
{
- // not yet associated with a resource, load
- std::size_t urlHash(0);
- RequestPathHashMap::const_iterator it;
- for( it = mUrlCache.begin(); it != mUrlCache.end(); ++it )
- {
- if( it->second == req->GetId() )
- {
- urlHash = it->first;
- break;
- }
- }
- DALI_ASSERT_DEBUG( it!=mUrlCache.end() );
+ // Not yet associated with a ticketed async resource transaction, so attempt to
+ // find a cached one and issue a new load if there isn't one in-flight:
- ticket = FindCompatibleResource( req->url, urlHash, req->attributes );
+ const std::size_t urlHash = GetHashForCachedRequest( request );
+ ticket = FindCompatibleResource( request.url, urlHash, request.attributes );
if( !ticket )
{
- // didn't find compatible resource
- ticket = IssueLoadRequest( req->url, req->attributes );
+ // Didn't find compatible resource already being loaded
+ ticket = IssueLoadRequest( request.url, request.attributes );
}
- req->resourceId = ticket->GetId();
+ request.resourceId = ticket->GetId();
}
else
{
ticket = mResourceClient.RequestResourceTicket( resId );
if( !ticket )
{
- // resource has been discarded since
- ticket = IssueLoadRequest( req->url, req->attributes );
- req->resourceId = ticket->GetId();
+ // Resource has been discarded since last load
+ ticket = IssueLoadRequest( request.url, request.attributes );
+ request.resourceId = ticket->GetId();
}
DALI_ASSERT_DEBUG( ticket->GetTypePath().type->id == ResourceBitmap ||
ticket->GetTypePath().type->id == ResourceNativeImage ||
// In this case both requests will be associated with the resource of size (40, 40)
// If image changes on filesystem to size (96, 96) -> now after reloading Req2 would load a
// new resource of size (96, 96), but reloading Req1 would load a scaled down version
-ResourceTicketPtr ImageFactory::Reload( Request* request )
+ResourceTicketPtr ImageFactory::Reload( Request& request )
{
- DALI_ASSERT_ALWAYS( request );
+ DALI_ASSERT_ALWAYS( &request );
// go through requests, check real size and attributes again. If different, update related ticket.
ResourceTicketPtr ticket;
- if( !request->resourceId )
+ if( !request.resourceId )
{
// in case of OnDemand loading, just return
return NULL;
}
- ticket = mResourceClient.RequestResourceTicket( request->resourceId );
+ ticket = mResourceClient.RequestResourceTicket( request.resourceId );
// ticket might have been deleted, eg. Image::Disconnect
if( !ticket )
{
- ticket = IssueLoadRequest( request->url, request->attributes );
- request->resourceId = ticket->GetId();
+ ticket = IssueLoadRequest( request.url, request.attributes );
+ request.resourceId = ticket->GetId();
}
else // ticket still alive
{
}
Vector2 size;
- Internal::ThreadLocalStorage::Get().GetPlatformAbstraction().GetClosestImageSize( request->url, *request->attributes, size );
+ Internal::ThreadLocalStorage::Get().GetPlatformAbstraction().GetClosestImageSize( request.url, *request.attributes, size );
const ImageAttributes& attrib = static_cast<ImageTicket*>(ticket.Get())->GetAttributes();
else
{
// if not, return a different ticket
- ticket = IssueLoadRequest( request->url, request->attributes );
- request->resourceId = ticket->GetId();
+ ticket = IssueLoadRequest( request.url, request.attributes );
+ request.resourceId = ticket->GetId();
}
}
return ticket;
// get cached request
RequestIdMap::iterator foundRequestIter = mRequestCache.find( cachedReqId );
- DALI_ASSERT_DEBUG( foundRequestIter != mRequestCache.end() );
+ DALI_ASSERT_DEBUG( foundRequestIter != mRequestCache.end() && "Only requests that are live in mRequestCache should appear in mUrlCache which is an index to speed-up lookups into it.");
if( foundRequestIter != mRequestCache.end() )
{
const Request& cachedRequest = *(foundRequestIter->second);
}
}
+std::size_t ImageFactory::GetHashForCachedRequest( const Request& request )
+{
+ const RequestId requestId = request.GetId();
+ std::size_t locatorHash(0);
+ RequestPathHashMap::const_iterator it;
+
+ for( it = mUrlCache.begin(); it != mUrlCache.end(); ++it )
+ {
+ if( it->second == requestId )
+ {
+ locatorHash = it->first;
+ break;
+ }
+ }
+ DALI_ASSERT_DEBUG( it!=mUrlCache.end() && "Only already-cached requests can have their locator hashes looked-up." );
+ return locatorHash;
+}
+
} // namespace Internal
} // namespace Dali