Merge "Merge branch 'devel/new_mesh' into devel/master" into devel/master
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-internal / utc-Dali-Internal-ImageFactory.cpp
index 59bc9ad..4d28e20 100644 (file)
 #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
 {
@@ -67,14 +68,14 @@ int UtcDaliImageFactoryUseCachedRequest01(void)
 
   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();
@@ -83,7 +84,7 @@ int UtcDaliImageFactoryUseCachedRequest01(void)
   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();
@@ -99,7 +100,7 @@ int UtcDaliImageFactoryUseCachedRequest02(void)
   // 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();
@@ -124,7 +125,7 @@ int UtcDaliImageFactoryUseCachedRequest02(void)
   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();
@@ -133,7 +134,7 @@ int UtcDaliImageFactoryUseCachedRequest02(void)
   application.GetPlatform().ResetTrace();
 
   // Resource is reloaded
-  Image image3 = Image::New( gTestImageFilename );
+  Image image3 = ResourceImage::New( gTestImageFilename );
 
   application.SendNotification();
   application.Render();
@@ -153,22 +154,22 @@ int UtcDaliImageFactoryUseCachedRequest03(void)
   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;
 }
@@ -181,10 +182,10 @@ int UtcDaliImageFactoryUseCachedRequest04(void)
 
   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;
@@ -203,7 +204,7 @@ int UtcDaliImageFactoryCompatibleResource01(void)
 
   // 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();
@@ -213,10 +214,11 @@ int UtcDaliImageFactoryCompatibleResource01(void)
   // 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
@@ -231,12 +233,12 @@ int UtcDaliImageFactoryCompatibleResource02(void)
 
   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();
@@ -244,23 +246,57 @@ int UtcDaliImageFactoryCompatibleResource02(void)
   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)
 {
@@ -278,7 +314,7 @@ 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();
@@ -291,7 +327,7 @@ int UtcDaliImageFactoryCompatibleResource03(void)
   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
@@ -310,12 +346,12 @@ int UtcDaliImageFactoryReload01(void)
   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;
 }
@@ -332,7 +368,7 @@ int UtcDaliImageFactoryReload02(void)
   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();
@@ -342,7 +378,7 @@ int UtcDaliImageFactoryReload02(void)
   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();
@@ -356,7 +392,7 @@ int UtcDaliImageFactoryReload02(void)
   // emulate load success
   EmulateImageLoaded( application, 80, 80 );
 
-  ResourceTicketPtr ticket3 = imageFactory.Reload( req.Get() );
+  ResourceTicketPtr ticket3 = imageFactory.Reload( *req.Get() );
 
   application.SendNotification();
   application.Render();
@@ -367,7 +403,7 @@ int UtcDaliImageFactoryReload02(void)
   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();
@@ -390,7 +426,7 @@ int UtcDaliImageFactoryReload03(void)
   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();
@@ -402,10 +438,10 @@ int UtcDaliImageFactoryReload03(void)
   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;
 }
@@ -422,7 +458,7 @@ int UtcDaliImageFactoryReload04(void)
   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();
@@ -430,7 +466,7 @@ int UtcDaliImageFactoryReload04(void)
   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();
@@ -444,7 +480,7 @@ int UtcDaliImageFactoryReload04(void)
   // emulate load success
   EmulateImageLoaded( application, 80, 80 );
 
-  ResourceTicketPtr ticket3 = imageFactory.Reload( req.Get() );
+  ResourceTicketPtr ticket3 = imageFactory.Reload( *req.Get() );
 
   application.SendNotification();
   application.Render();
@@ -457,7 +493,7 @@ int UtcDaliImageFactoryReload04(void)
   application.GetPlatform().ResetTrace();
 
   // still loading
-  ticket3 = imageFactory.Reload( req.Get() );
+  ticket3 = imageFactory.Reload( *req.Get() );
   application.SendNotification();
   application.Render();
   application.SendNotification();
@@ -490,13 +526,13 @@ int UtcDaliImageFactoryReload05(void)
   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();
@@ -505,7 +541,7 @@ int UtcDaliImageFactoryReload05(void)
   DALI_TEST_CHECK( ticket );
   application.GetPlatform().ResetTrace();
 
-  ticket = imageFactory.Reload( req.Get() );
+  ticket = imageFactory.Reload( *req.Get() );
 
   application.SendNotification();
   application.Render();
@@ -518,7 +554,7 @@ int UtcDaliImageFactoryReload05(void)
   // emulate load success
   EmulateImageLoaded( application, 80, 80 );
 
-  ticket = imageFactory.Reload( req.Get() );
+  ticket = imageFactory.Reload( *req.Get() );
 
   application.SendNotification();
   application.Render();
@@ -540,12 +576,12 @@ int UtcDaliImageFactoryReload06(void)
 
   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();
@@ -553,16 +589,16 @@ int UtcDaliImageFactoryReload06(void)
   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
@@ -571,14 +607,14 @@ int UtcDaliImageFactoryReload06(void)
   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;