#include <dali/internal/event/common/thread-local-storage.h>
#include <dali/internal/event/images/image-factory.h>
#include <dali/internal/event/resources/resource-ticket.h>
+#include <dali/internal/common/image-attributes.h>
using namespace Dali;
using Internal::ResourceTicketPtr;
using Internal::ImageFactory;
using Internal::ImageFactoryCache::RequestPtr;
-
+using Internal::ImageAttributes;
namespace
{
tet_infoline( "UtcDaliImageFactoryCachedRequest01 - Request same image more than once" );
- Image image = Image::New( gTestImageFilename );
+ Image image = ResourceImage::New( gTestImageFilename );
application.SendNotification();
application.Render();
DALI_TEST_CHECK( application.GetPlatform().WasCalled( TestPlatformAbstraction::LoadResourceFunc ) );
application.GetPlatform().ResetTrace();
- Image image2 = Image::New( gTestImageFilename );
+ Image image2 = ResourceImage::New( gTestImageFilename );
application.SendNotification();
application.Render();
DALI_TEST_CHECK( !application.GetPlatform().WasCalled( TestPlatformAbstraction::LoadResourceFunc ) );
application.GetPlatform().ResetTrace();
- Image image3 = Image::New( gTestImageFilename );
+ Image image3 = ResourceImage::New( gTestImageFilename );
application.SendNotification();
application.Render();
// testing resource deletion when taken off stage
tet_infoline( "UtcDaliImageFactoryCachedRequest02 - Discard previously requested resource" );
- Image image = Image::New( gTestImageFilename, Image::Immediate, Image::Unused );
+ Image image = ResourceImage::New( gTestImageFilename, ResourceImage::IMMEDIATE, Image::UNUSED );
ImageActor actor = ImageActor::New( image );
application.SendNotification();
application.SendNotification();
// Should find stale request in cache, so load image from filesystem
- Image image2 = Image::New( gTestImageFilename );
+ Image image2 = ResourceImage::New( gTestImageFilename );
application.SendNotification();
application.Render();
application.GetPlatform().ResetTrace();
// Resource is reloaded
- Image image3 = Image::New( gTestImageFilename );
+ Image image3 = ResourceImage::New( gTestImageFilename );
application.SendNotification();
application.Render();
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 );
+ ImageAttributes attr = ImageAttributes::New( 80, 160);
req2 = imageFactory.RegisterRequest( gTestImageFilename, &attr );
- ResourceTicketPtr ticket4 = imageFactory.Load( req2.Get() );
+ ResourceTicketPtr ticket4 = imageFactory.Load( *req2.Get() );
DALI_TEST_CHECK( req != req2 );
END_TEST;
}
ImageFactory& imageFactory = Internal::ThreadLocalStorage::Get().GetImageFactory();
- ImageAttributes attr = ImageAttributes::New( 80, 160, Pixel::BGR8888 );
+ ImageAttributes attr = ImageAttributes::New( 80, 160 );
RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, &attr );
- ImageAttributes attr2 = ImageAttributes::New( 80, 160, Pixel::BGR8888 );
+ ImageAttributes attr2 = ImageAttributes::New( 80, 160 );
RequestPtr req2 = imageFactory.RegisterRequest( gTestImageFilename, &attr2 );
DALI_TEST_EQUALS( req, req2, TEST_LOCATION );
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();
// emulate load success
EmulateImageLoaded( application, 80, 80 );
+ // Request a second load using exact-match image size:
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
ImageFactory& imageFactory = Internal::ThreadLocalStorage::Get().GetImageFactory();
- Vector2 testSize(80.0f, 80.0f);
- application.GetPlatform().SetClosestImageSize(testSize);
+ 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() );
+ ResourceTicketPtr ticket = imageFactory.Load( *req.Get() );
application.SendNotification();
application.Render();
application.Render();
// emulate load success
- EmulateImageLoaded( application, 80, 80 );
+ 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.
+ // 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( 92, 92 );
+ attr.SetSize( testSize.x + 1, testSize.y + 1 );
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
END_TEST;
}
+// 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)
{
// 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();
ImageFactory& imageFactory = Internal::ThreadLocalStorage::Get().GetImageFactory();
- Vector2 testSize(80.0f, 80.0f);
- application.GetPlatform().SetClosestImageSize(testSize);
+ 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() );
+ ResourceTicketPtr ticket = imageFactory.Load( *req.Get() );
application.SendNotification();
application.Render();
application.Render();
// emulate load success
- EmulateImageLoaded( application, 80, 80 );
+ 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( 92, 92 );
+ attr.SetSize( testSize.x + 1, testSize.y + 1 );
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 );
+ EmulateImageLoaded( application, testSize.x + 1, testSize.y + 1 );
// 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;