(ImageSize) Add natural image size handling
authorDavid Steele <david.steele@partner.samsung.com>
Tue, 25 Feb 2014 13:25:04 +0000 (13:25 +0000)
committerPaul Wisbey <p.wisbey@samsung.com>
Mon, 3 Mar 2014 18:34:53 +0000 (18:34 +0000)
[Issue#]       N/A
[Problem]      Need a way of switching actor between natural image size and
constrained, animated or set size.
[Cause]        Natural image size not handled correctly
[Solution]     Add mechanism to switch to natural size, (using existing
Actor::SetSize() will override this)
[Verification] Build Repo

Change-Id: Id4641d87bc8de68e613a0e10d8dddf26cddae9fb
Signed-off-by: David Steele <david.steele@partner.samsung.com>
17 files changed:
automated-tests/dali-internal-test-suite/image-factory/utc-Dali-ImageFactory.cpp
automated-tests/dali-test-suite-utils/test-platform-abstraction.h
automated-tests/dali-test-suite/actors/utc-Dali-ImageActor.cpp
automated-tests/dali-test-suite/actors/utc-Dali-TextActor.cpp
automated-tests/dali-test-suite/images/utc-Dali-Image.cpp
automated-tests/dali-test-suite/render-tasks/utc-Dali-RenderTask.cpp
automated-tests/tet_scen
capi/dali/public-api/actors/image-actor.h
capi/dali/public-api/actors/text-actor.h
dali/internal/event/actors/image-actor-impl.cpp
dali/internal/event/actors/image-actor-impl.h
dali/internal/event/actors/text-actor-impl.cpp
dali/internal/event/actors/text-actor-impl.h
dali/internal/event/images/image-impl.cpp
dali/internal/event/images/image-impl.h
dali/public-api/actors/image-actor.cpp
dali/public-api/actors/text-actor.cpp

index 51e63b0..66a7595 100644 (file)
@@ -234,7 +234,7 @@ static void UtcDaliImageFactoryCompatibleResource01()
   ImageFactory& imageFactory  = Internal::ThreadLocalStorage::Get().GetImageFactory();
 
   Vector2 testSize(80.0f, 80.0f);
-  application.GetPlatform().SetImageMetaDataSize(testSize);
+  application.GetPlatform().SetClosestImageSize(testSize);
 
   // request with default attributes ( size is 0,0 )
   RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL );
@@ -266,7 +266,7 @@ static void UtcDaliImageFactoryCompatibleResource02()
   ImageFactory& imageFactory  = Internal::ThreadLocalStorage::Get().GetImageFactory();
 
   Vector2 testSize(80.0f, 80.0f);
-  application.GetPlatform().SetImageMetaDataSize(testSize);
+  application.GetPlatform().SetClosestImageSize(testSize);
 
   // request with default attributes ( size is 0,0 )
   RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL );
@@ -303,7 +303,7 @@ static void UtcDaliImageFactoryCompatibleResource03()
   ImageFactory& imageFactory  = Internal::ThreadLocalStorage::Get().GetImageFactory();
 
   Vector2 testSize(80.0f, 80.0f);
-  application.GetPlatform().SetImageMetaDataSize(testSize);
+  application.GetPlatform().SetClosestImageSize(testSize);
 
   // this time use defined attributes, nut just NULL
   ImageAttributes attr = ImageAttributes::New();
@@ -337,7 +337,7 @@ static void UtcDaliImageFactoryReload01()
   tet_infoline( "UtcDaliImageFactoryReload01 - Reload unchanged image" );
 
   Vector2 testSize(80.0f, 80.0f);
-  application.GetPlatform().SetImageMetaDataSize(testSize);
+  application.GetPlatform().SetClosestImageSize(testSize);
 
   ImageFactory& imageFactory  = Internal::ThreadLocalStorage::Get().GetImageFactory();
 
@@ -360,7 +360,7 @@ static void UtcDaliImageFactoryReload02()
   ImageFactory& imageFactory  = Internal::ThreadLocalStorage::Get().GetImageFactory();
 
   Vector2 testSize(80.0f, 80.0f);
-  application.GetPlatform().SetImageMetaDataSize(testSize);
+  application.GetPlatform().SetClosestImageSize(testSize);
 
   RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL );
   ResourceTicketPtr ticket = imageFactory.Load( req.Get() );
@@ -417,7 +417,7 @@ static void UtcDaliImageFactoryReload03()
   ImageFactory& imageFactory  = Internal::ThreadLocalStorage::Get().GetImageFactory();
 
   Vector2 testSize( 80.0f, 80.0f );
-  application.GetPlatform().SetImageMetaDataSize( testSize );
+  application.GetPlatform().SetClosestImageSize( testSize );
 
   RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL );
   ResourceTicketPtr ticket = imageFactory.Load( req.Get() );
@@ -429,7 +429,7 @@ static void UtcDaliImageFactoryReload03()
   EmulateImageLoaded( application, 80, 80 );
 
   Vector2 newSize( 192.0f, 192.0f );
-  application.GetPlatform().SetImageMetaDataSize( newSize );
+  application.GetPlatform().SetClosestImageSize( newSize );
 
   // Image file changed size, new resource request should be issued
   ResourceTicketPtr ticket2 = imageFactory.Reload( req.Get() );
@@ -448,7 +448,7 @@ static void UtcDaliImageFactoryReload04()
   ImageFactory& imageFactory  = Internal::ThreadLocalStorage::Get().GetImageFactory();
 
   Vector2 testSize(80.0f, 80.0f);
-  application.GetPlatform().SetImageMetaDataSize(testSize);
+  application.GetPlatform().SetClosestImageSize(testSize);
 
   RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL );
   ResourceTicketPtr ticket = imageFactory.Load( req.Get() );
@@ -506,7 +506,7 @@ static void UtcDaliImageFactoryReload05()
   ImageFactory& imageFactory  = Internal::ThreadLocalStorage::Get().GetImageFactory();
 
   Vector2 testSize(80.0f, 80.0f);
-  application.GetPlatform().SetImageMetaDataSize(testSize);
+  application.GetPlatform().SetClosestImageSize(testSize);
 
   RequestPtr req;
   ImageAttributes attr = ImageAttributes::New();
@@ -568,7 +568,7 @@ static void UtcDaliImageFactoryReload06()
   ImageFactory& imageFactory  = Internal::ThreadLocalStorage::Get().GetImageFactory();
 
   Vector2 testSize(80.0f, 80.0f);
-  application.GetPlatform().SetImageMetaDataSize(testSize);
+  application.GetPlatform().SetClosestImageSize(testSize);
 
   // request with default attributes ( size is 0,0 )
   RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL );
@@ -595,7 +595,7 @@ static void UtcDaliImageFactoryReload06()
   DALI_TEST_EQUALS( ticket->GetId(), ticket2->GetId(), TEST_LOCATION ); // same resource
 
   Vector2 newSize(512.0f, 512.0f);
-  application.GetPlatform().SetImageMetaDataSize(newSize);
+  application.GetPlatform().SetClosestImageSize(newSize);
 
   // reload fixed size (192,192) request
   ticket2 = imageFactory.Reload( req2.Get() );
index fe01399..5c8536a 100644 (file)
@@ -117,7 +117,7 @@ public:
                                     const ImageAttributes& attributes,
                                     Vector2& closestSize)
   {
-    closestSize = mSize;
+    closestSize = mClosestSize;
     mTrace.PushCall("GetClosestImageSize", "");
   }
 
@@ -125,7 +125,7 @@ public:
                                     const ImageAttributes& attributes,
                                     Vector2& closestSize)
   {
-    closestSize = mSize;
+    closestSize = mClosestSize;
     mTrace.PushCall("GetClosestImageSize", "");
   }
 
@@ -658,9 +658,9 @@ public: // TEST FUNCTIONS
     mRequest = NULL;
   }
 
-  void SetImageMetaDataSize(const Vector2& size)
+  void SetClosestImageSize(const Vector2& size)
   {
-    mSize = size;
+    mClosestSize = size;
   }
 
   void SetLoadFileResult( bool result, std::vector< unsigned char >& buffer )
@@ -705,6 +705,7 @@ private:
   Resources                     mResources;
   Integration::ResourceRequest* mRequest;
   Vector2                       mSize;
+  Vector2                       mClosestSize;
   bool                          mReadGlobalMetricsResult;
   bool                          mReadMetricsResult;
   Integration::GlobalMetrics mReadGlobalMetrics;
index d7cc084..2c36424 100644 (file)
@@ -55,7 +55,13 @@ TEST_FUNCTION( UtcDaliImageActorDownCast,             POSITIVE_TC_IDX );
 TEST_FUNCTION( UtcDaliImageActorDownCast2,            NEGATIVE_TC_IDX );
 TEST_FUNCTION( UtcDaliImageActor9Patch,               POSITIVE_TC_IDX );
 TEST_FUNCTION( UtcDaliImageActorPixelArea,            POSITIVE_TC_IDX );
-TEST_FUNCTION( UtcDaliImageActorGetCurrentImageSize,  POSITIVE_TC_IDX );
+TEST_FUNCTION( UtcDaliImageActorGetCurrentImageSize01,POSITIVE_TC_IDX );
+TEST_FUNCTION( UtcDaliImageActorGetCurrentImageSize02,POSITIVE_TC_IDX );
+TEST_FUNCTION( UtcDaliImageActorGetCurrentImageSize03,POSITIVE_TC_IDX );
+TEST_FUNCTION( UtcDaliImageActorGetCurrentImageSize04,POSITIVE_TC_IDX );
+TEST_FUNCTION( UtcDaliImageActorGetCurrentImageSize05,POSITIVE_TC_IDX );
+TEST_FUNCTION( UtcDaliImageActorNaturalPixelAreaSize01, POSITIVE_TC_IDX );
+TEST_FUNCTION( UtcDaliImageActorNaturalPixelAreaSize02, POSITIVE_TC_IDX );
 TEST_FUNCTION( UtcDaliImageActorDefaultProperties,    POSITIVE_TC_IDX );
 TEST_FUNCTION( UtcDaliImageActorUseImageAlpha01,      POSITIVE_TC_IDX );
 TEST_FUNCTION( UtcDaliImageActorUseImageAlpha02,      POSITIVE_TC_IDX );
@@ -223,17 +229,20 @@ static void UtcDaliImageActorPixelArea()
   DALI_TEST_EQUALS( 8, actor2.GetPixelArea().height, TEST_LOCATION );
 }
 
-static void UtcDaliImageActorGetCurrentImageSize()
+static void UtcDaliImageActorGetCurrentImageSize01()
 {
   TestApplication application;
   tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize");
 
-  BitmapImage image = BitmapImage::New( 100, 50 );
+  Vector2 initialImageSize(100, 50);
+  BitmapImage image = BitmapImage::New( initialImageSize.width, initialImageSize.height );
   ImageActor actor = ImageActor::New( image );
+  Stage::GetCurrent().Add(actor);
+
   application.SendNotification();
   application.Render();
-  application.Render();
-  application.SendNotification();
+
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), initialImageSize, TEST_LOCATION );
 
   Vector2 size(200.0f, 200.0f);
   actor.SetSize(size);
@@ -255,6 +264,412 @@ static void UtcDaliImageActorGetCurrentImageSize()
   DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2( area.width, area.height ), TEST_LOCATION );
 }
 
+
+static void UtcDaliImageActorGetCurrentImageSize02()
+{
+  TestApplication application;
+  tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - Test that using an image resource sets the actor size with it's natural size immediately rather than on load");
+
+  Vector2 initialImageSize(100, 50);
+
+  application.GetPlatform().SetClosestImageSize(initialImageSize);
+
+  Image image = Image::New("image.jpg");
+  ImageActor actor = ImageActor::New( image );
+  Stage::GetCurrent().Add(actor);
+
+  application.SendNotification(); // Flush update messages
+  application.Render();           // Process resource request
+  application.SendNotification(); // Flush update messages
+  application.Render();           // Process resource request
+
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), initialImageSize, TEST_LOCATION );
+
+  // Now complete the image load
+  Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
+  Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
+  bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  initialImageSize.width,initialImageSize.height, initialImageSize.width,initialImageSize.height );
+
+  Integration::ResourcePointer resourcePtr(bitmap); // reference it
+  application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
+  application.Render();           // Process LoadComplete
+  application.SendNotification(); // Process event messages
+  application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
+  application.GetPlatform().ClearReadyResources(); //
+
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), initialImageSize, TEST_LOCATION );
+
+  Vector2 size(200.0f, 200.0f);
+  actor.SetSize(size);
+
+  // flush the queue and render once
+  application.SendNotification();
+  application.Render();
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
+
+  actor.SetToNaturalSize();
+  application.SendNotification();
+  application.Render();
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), initialImageSize, TEST_LOCATION );
+}
+
+
+static void UtcDaliImageActorGetCurrentImageSize03()
+{
+  TestApplication application;
+  tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - Test that using an image resource with a requested size sets the actor size with it's nearest size immediately rather than on load");
+
+  Vector2 closestImageSize( 80, 45);
+
+  application.GetPlatform().SetClosestImageSize(closestImageSize);
+
+  ImageAttributes attrs;
+  attrs.SetSize(40, 30);
+  Image image = Image::New("image.jpg", attrs);
+  ImageActor actor = ImageActor::New( image );
+  Stage::GetCurrent().Add(actor);
+
+  application.SendNotification(); // Flush update messages
+  application.Render();           // Process resource request
+  application.SendNotification(); // Flush update messages
+  application.Render();           // Process resource request
+
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
+
+  // Now complete the image load
+  Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
+  Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
+  bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
+
+  Integration::ResourcePointer resourcePtr(bitmap); // reference it
+  application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
+  application.Render();           // Process LoadComplete
+  application.SendNotification(); // Process event messages
+  application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
+  application.GetPlatform().ClearReadyResources(); //
+
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
+
+  // Test that setting a size on the actor can be 'undone' with SetNaturalSize()
+  Vector2 size(200.0f, 200.0f);
+  actor.SetSize(size);
+
+  // flush the queue and render once
+  application.SendNotification();
+  application.Render();
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
+
+  actor.SetToNaturalSize();
+  application.SendNotification();
+  application.Render();
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
+}
+
+
+static void UtcDaliImageActorGetCurrentImageSize04()
+{
+  TestApplication application;
+  tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - check a new image doesn't change a set actor size");
+
+  Vector2 closestImageSize( 80, 45);
+  application.GetPlatform().SetClosestImageSize(closestImageSize);
+
+  ImageAttributes attrs;
+  attrs.SetSize(40, 30); // Request a really small size we won't get.
+  Image image = Image::New("image.jpg", attrs);
+  ImageActor actor = ImageActor::New( image );
+  Stage::GetCurrent().Add(actor);
+
+  application.SendNotification(); // Flush update messages
+  application.Render();           // Process resource request
+
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
+
+  // Now complete the image load
+  Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
+  Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
+  bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
+
+  Integration::ResourcePointer resourcePtr(bitmap); // reference it
+  application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
+  application.Render();           // Process LoadComplete
+  application.SendNotification(); // Process event messages
+  application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
+  application.GetPlatform().ClearReadyResources(); //
+
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
+
+  Vector2 size(200.0f, 200.0f);
+  actor.SetSize(size);
+
+  // flush the queue and render once
+  application.SendNotification();
+  application.Render();
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
+
+  // Load a different image
+
+  Vector2 image2ClosestSize = Vector2(240, 150); // The actual size image loader will return for the request below
+  application.GetPlatform().SetClosestImageSize(image2ClosestSize);
+
+  attrs.SetSize(100, 100);
+  Image image2 = Image::New("image2.jpg", attrs);
+  actor.SetImage(image2);
+
+  application.SendNotification(); // Flush update messages
+  application.Render();           // Process resource request
+  application.SendNotification(); // Flush update messages
+  application.Render();           // Process resource request
+
+  // Ensure the actor size is kept
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
+
+  // Now complete the image load
+  req = application.GetPlatform().GetRequest();
+  Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
+  bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
+
+  Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
+  application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2);
+  application.Render();           // Process LoadComplete
+  application.SendNotification(); // Process event messages
+  application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
+  application.GetPlatform().ClearReadyResources(); //
+
+  // Ensure the actor size is kept
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), size, TEST_LOCATION );
+
+  actor.SetToNaturalSize();
+  application.SendNotification();
+  application.Render();
+  // Ensure the actor size gets the new image's natural size
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), image2ClosestSize, TEST_LOCATION );
+}
+
+
+static void UtcDaliImageActorGetCurrentImageSize05()
+{
+  TestApplication application;
+  tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - check a new image doens't change actor size until load complete");
+
+  Vector2 closestImageSize( 80, 45);
+  application.GetPlatform().SetClosestImageSize(closestImageSize);
+
+  ImageAttributes attrs;
+  attrs.SetSize(40, 30); // Request a really small size we won't get.
+  Image image = Image::New("image.jpg", attrs);
+  ImageActor actor = ImageActor::New( image );
+  Stage::GetCurrent().Add(actor);
+
+  application.SendNotification(); // Flush update messages
+  application.Render();           // Process resource request
+
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
+
+  // Now complete the image load
+  Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
+  Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
+  bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
+
+  Integration::ResourcePointer resourcePtr(bitmap); // reference it
+  application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
+  application.Render();           // Process LoadComplete
+  application.SendNotification(); // Process event messages
+  application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
+  application.GetPlatform().ClearReadyResources(); //
+
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
+
+  // Load a different image
+
+  Vector2 image2ClosestSize = Vector2(240, 150);
+  application.GetPlatform().SetClosestImageSize(image2ClosestSize);
+
+  attrs.SetSize(100, 100);
+  Image image2 = Image::New("image2.jpg", attrs);
+  actor.SetImage(image2);
+
+  application.SendNotification(); // Flush update messages
+  application.Render();           // Process resource request
+  application.SendNotification(); // Flush update messages
+  application.Render();           // Process resource request
+
+  // Ensure the actor size is kept
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
+
+  // Now complete the image load
+  req = application.GetPlatform().GetRequest();
+  Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
+  bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
+
+  Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
+  application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2);
+  application.Render();           // Process LoadComplete
+  application.SendNotification(); // Process event messages
+  application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
+  application.GetPlatform().ClearReadyResources(); //
+
+  application.SendNotification(); // Process event messages
+  application.Render();           // Process LoadComplete
+
+  // Ensure the actor size gets the new image's natural size
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), image2ClosestSize, TEST_LOCATION );
+}
+
+static void UtcDaliImageActorNaturalPixelAreaSize01()
+{
+  TestApplication application;
+  tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - check a new image doens't change actor size until load complete");
+
+//If an image is loaded without setting size, then the actor gets the natural size of the image
+//Setting the pixel area will change the actor size to match the pixel area
+//Setting the actor size will not change pixel area, and will cause the partial image to stretch
+//to the new size.
+//Clearing the pixel area will not change actor size, and the actor will show the whole image.
+
+
+  Vector2 closestImageSize( 80, 45);
+  application.GetPlatform().SetClosestImageSize(closestImageSize);
+
+  ImageAttributes attrs;
+  attrs.SetSize(40, 30); // Request a really small size we won't get.
+  Image image = Image::New("image.jpg", attrs);
+  ImageActor actor = ImageActor::New( image );
+  Stage::GetCurrent().Add(actor);
+
+  application.SendNotification(); // Flush update messages
+  application.Render();           // Process resource request
+
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
+  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
+
+  // Now complete the image load
+  Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
+  Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
+  bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
+
+  Integration::ResourcePointer resourcePtr(bitmap); // reference it
+  application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
+  application.Render();           // Process LoadComplete
+  application.SendNotification(); // Process event messages
+  application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
+  application.GetPlatform().ClearReadyResources(); //
+
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
+  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
+
+  // Set a pixel area on a naturally sized actor - expect the actor to take the
+  // pixel area as size
+  actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30));
+  application.SendNotification(); // Process event messages
+  application.Render();           // Process LoadComplete
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(30, 30), TEST_LOCATION );
+  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION );
+
+  // Set a size. Expect the partial image to stretch to fill the new size
+  actor.SetSize(100, 100);
+  application.SendNotification(); // Process event messages
+  application.Render();           // Process LoadComplete
+  application.Render();           // Process LoadComplete
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(30, 30), TEST_LOCATION );
+  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
+
+  // Clear the pixel area. Expect the whole image to be shown, filling the set size.
+  actor.ClearPixelArea();
+  application.SendNotification(); // Process event messages
+  application.Render();           // Process LoadComplete
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(100, 100), TEST_LOCATION );
+  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
+}
+
+static void UtcDaliImageActorNaturalPixelAreaSize02()
+{
+  TestApplication application;
+  tet_infoline("Positive test for Dali::ImageActor::GetCurrentImageSize - check a new image doens't change actor size until load complete");
+
+//If an image is loaded without setting size, then the actor gets the natural size of the image
+//Setting the pixel area will change the actor size to match the pixel area
+//Setting the actor size will not change pixel area, and will cause the partial image to stretch
+//to the new size.
+//Clearing the pixel area will not change actor size, and the actor will show the whole image.
+
+
+  Vector2 closestImageSize( 80, 45);
+  application.GetPlatform().SetClosestImageSize(closestImageSize);
+
+  ImageAttributes attrs;
+  attrs.SetSize(40, 30); // Request a really small size we won't get.
+  Image image = Image::New("image.jpg", attrs);
+  ImageActor actor = ImageActor::New( image );
+  Stage::GetCurrent().Add(actor);
+
+  application.SendNotification(); // Flush update messages
+  application.Render();           // Process resource request
+
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
+  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
+
+  // Now complete the image load
+  Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
+  Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false );
+  bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888,  closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
+
+  Integration::ResourcePointer resourcePtr(bitmap); // reference it
+  application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
+  application.Render();           // Process LoadComplete
+  application.SendNotification(); // Process event messages
+  application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
+  application.GetPlatform().ClearReadyResources(); //
+
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
+  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
+
+  // Set a pixel area on a naturally sized actor - expect the actor to take the
+  // pixel area as size
+  actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30));
+  application.SendNotification(); // Process event messages
+  application.Render();           // Process LoadComplete
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(30, 30), TEST_LOCATION );
+  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION );
+
+  // Clear the pixel area. Expect the whole image to be shown, changing actor size
+  actor.ClearPixelArea();
+  application.SendNotification(); // Process event messages
+  application.Render();           // Process LoadComplete
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
+  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
+
+  // Set a size. Expect the partial image to stretch to fill the new size
+  actor.SetSize(100, 100);
+  application.SendNotification(); // Process event messages
+  application.Render();           // Process LoadComplete
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(100, 100), TEST_LOCATION );
+  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
+
+  // Set a pixel area, don't expect size to change
+  actor.SetPixelArea(ImageActor::PixelArea(0, 0, 40, 40));
+  application.SendNotification(); // Process event messages
+  application.Render();           // Process LoadComplete
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(40, 40), TEST_LOCATION );
+  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
+
+  // Use natural size - expect actor to change to pixel area
+  actor.SetToNaturalSize();
+  application.SendNotification(); // Process event messages
+  application.Render();           // Process LoadComplete
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), Vector2(40, 40), TEST_LOCATION );
+  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(40, 40), TEST_LOCATION );
+
+  // Clearing pixel area should change actor size to image size
+  actor.ClearPixelArea();
+  application.SendNotification(); // Process event messages
+  application.Render();           // Process LoadComplete
+  DALI_TEST_EQUALS( actor.GetCurrentImageSize(), closestImageSize, TEST_LOCATION );
+  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), closestImageSize, TEST_LOCATION );
+}
+
+
+
 static void UtcDaliImageActorDefaultProperties()
 {
   TestApplication application;
index 5b31c08..dd7e67a 100644 (file)
@@ -773,7 +773,7 @@ static void UtcDaliTextActorAutomaticSizeSet()
   DALI_TEST_EQUALS( Vector2( 10.0f, 11.0f ), actor.GetCurrentSize().GetVectorXY(), TEST_LOCATION );
 
   // set text to its natural size
-  actor.SetNaturalSize();
+  actor.SetToNaturalSize();
   // render a frame
   application.SendNotification();
   application.Render();
@@ -831,7 +831,7 @@ static void UtcDaliTextActorAutomaticSizeSetAnimation()
   DALI_TEST_EQUALS( animationTargetSize, actor.GetCurrentSize(), TEST_LOCATION );
 
   // set text to its natural size
-  actor.SetNaturalSize();
+  actor.SetToNaturalSize();
   // render a frame
   application.SendNotification();
   application.Render();
index 0053f5c..119ed7e 100644 (file)
@@ -750,7 +750,7 @@ static void UtcDaliImageGetImageSize()
   tet_infoline("UtcDaliImageGetImageSize - Image::GetImageSize()");
 
   Vector2 testSize(8.0f, 16.0f);
-  platform.SetImageMetaDataSize(testSize);
+  platform.SetClosestImageSize(testSize);
 
   Vector2 size = Image::GetImageSize(gTestImageFilename);
 
@@ -919,7 +919,7 @@ static void UtcDaliImageSignalUploaded()
 
   // set up image in fake platform abstraction
   Vector2 testSize(80.0f, 80.0f);
-  application.GetPlatform().SetImageMetaDataSize(testSize);
+  application.GetPlatform().SetClosestImageSize(testSize);
 
   Image image = Image::New(gTestImageFilename);
   image.LoadingFinishedSignal().Connect( SignalLoadHandler );
index ff6630a..fb99a4f 100644 (file)
@@ -332,7 +332,7 @@ void ReloadImage(TestApplication& application, Image image)
   application.GetPlatform().ClearReadyResources();
   application.GetPlatform().DiscardRequest();
   application.GetPlatform().ResetTrace();
-  application.GetPlatform().SetImageMetaDataSize(Vector2(80.0f, 80.0f)); // Ensure reload is called.
+  application.GetPlatform().SetClosestImageSize(Vector2(80.0f, 80.0f)); // Ensure reload is called.
   image.Reload();
 }
 
index b65ed90..8ec3104 100644 (file)
@@ -108,6 +108,6 @@ image-factory
 # If you just want to compile/execute only certain TET cases, then you can do as shown below.
 # Try not to check in your changes to the debug section.
 debug
-        /dali-test-suite/actors/utc-Dali-Handle
+        /dali-test-suite/actors/utc-Dali-ImageActor
 
 # EOF
index dd82f4d..af0c67e 100644 (file)
@@ -44,6 +44,23 @@ class ImageActor;
  * Allows the developer to add an actor to stage which displays the content of an Image object.
  *
  * By default CullFaceMode is set to CullNone to enable the ImageActor to be viewed from all angles.
+ *
+ * If an ImageActor is created without setting size, then the actor takes the size of the image -
+ * this is the natural size.
+ * Setting a size on the ImageActor, e.g through the SetSize api or through an animation will
+ * stop the natural size being used.
+ *
+ * Such a set size can be changed back to the image's size by calling SetToNaturalSize().
+ *
+ * If a pixel area is set on an ImageActor with natural size, the actor size will change
+ * to match the pixel area. If a pixel area is set on an ImageActor that has had it's size set,
+ * then the size doesn't change, and the partial image will be stretched to fill the set size.
+ *
+ * Clearing the pixel area on an Image actor with natural size will cause the actor to show the
+ * whole image again, and will change size back to that of the image.
+ *
+ * Clearing the pixel area on an Image actor with a set size will cause the actor to show the
+ * whole image again, but will not change the image size.
  */
 class DALI_IMPORT_API ImageActor : public RenderableActor
 {
@@ -139,9 +156,8 @@ public:
   static ImageActor New();
 
   /**
-   * Create a image actor object.
-   * When the image is loaded the actors size will reset to the image size,
-   * unless a custom size chosen via Actor:SetSize().
+   * Create a image actor object.  The actor will take the image's
+   * natural size unless a custom size is chosen, e.g. via Actor:SetSize()
    * @pre image must be initialized.
    * @param[in] image The image to display.
    * @return A handle to a newly allocated actor.
@@ -150,8 +166,8 @@ public:
 
   /**
    * Create a image actor object.
-   * When the image is loaded the actors size will reset to the pixelArea,
-   * unless a custom size was chosen via Actor:SetSize().
+   * When the image is loaded the actor's size will reset to the pixelArea,
+   * unless a custom size was chosen, e.g. via Actor:SetSize().
    * @pre image must be initialized.
    * @param [in] image The image to display.
    * @param [in] pixelArea The area of the image to display.
@@ -181,8 +197,9 @@ public:
 
   /**
    * Set the image rendered by the actor.
-   * When the image is loaded the actors size will be reset to the image size,
-   * unless a custom size was chosen via Actor:SetSize().
+   * When the image is loaded the actor's size will be reset to the image size,
+   * unless a custom size was chosen, e.g. via Actor:SetSize() or a pixel area
+   * was set.
    * @note The old image will continue to be displayed until the given image has loaded.
    * @pre image must be initialized.
    * @param [in] image The image to display.
@@ -196,9 +213,19 @@ public:
   Image GetImage();
 
   /**
+   * Tell the image actor to use the natural size of the current image
+   * or future images. Calling SetSize on this actor or animating the size
+   * of the actor overrides this behaviour.
+   * @post The image actor uses the natural image size after an image
+   * has been loaded.
+   * @note Actor::SetSizeSignal() will be triggered if there is a current image.
+   */
+  void SetToNaturalSize();
+
+  /**
    * Set a region of the image to display, in pixels.
-   * When the image is loaded the actors size will be reset to the pixelArea,
-   * unless a custom size chosen via Actor:SetSize().
+   * When the image is loaded the actor's size will be reset to the pixelArea,
+   * unless a custom size was chosen, e.g. via Actor:SetSize().
    * Note! PixelArea should be inside the image data size. It gets clamped by GL
    * @pre image must be initialized.
    * @param [in] pixelArea The area of the image to display.
@@ -222,6 +249,8 @@ public:
 
   /**
    * Remove any pixel areas specified with SetPixelArea; the entire image will be displayed.
+   * The actor size will change to that of the Image unless a custom size was set, e.g. via
+   * Actor::SetSize().
    * @pre image must be initialized.
    */
   void ClearPixelArea();
index 8ea936c..8f8b9b7 100644 (file)
@@ -233,7 +233,7 @@ public:
    * After this method the text actor always uses the natural size of the text
    * when SetText is called unless SetSize is called to override the size.
    */
-  void SetNaturalSize();
+  void SetToNaturalSize();
 
   /**
    * Get the font used to display the text label displayed by the actor
index da67e4c..7e9080d 100644 (file)
@@ -110,6 +110,7 @@ ImageActorPtr ImageActor::New( Image* image )
   {
     actor->mImageNext.Set( image, false );
     actor->OnImageSet( *image );
+    actor->SetNaturalSize( *image );
   }
 
   return actor;
@@ -167,9 +168,27 @@ Dali::Image ImageActor::GetImage()
   return mImageAttachment->GetImage();
 }
 
+void ImageActor::SetToNaturalSize()
+{
+  mUsingNaturalSize = true;
+  Dali::Image image = mImageAttachment->GetImage();
+
+  if( image )
+  {
+    SetNaturalSize( GetImplementation(image) );
+  }
+}
+
 void ImageActor::SetPixelArea( const PixelArea& pixelArea )
 {
   mImageAttachment->SetPixelArea( pixelArea );
+
+  if( mUsingNaturalSize )
+  {
+    mInternalSetSize = true;
+    SetSize(pixelArea.width, pixelArea.height);
+    mInternalSetSize = false;
+  }
 }
 
 const ImageActor::PixelArea& ImageActor::GetPixelArea() const
@@ -185,6 +204,17 @@ bool ImageActor::IsPixelAreaSet() const
 void ImageActor::ClearPixelArea()
 {
   mImageAttachment->ClearPixelArea();
+
+  if( mUsingNaturalSize )
+  {
+    Dali::Image image = mImageAttachment->GetImage();
+    if( image )
+    {
+      mInternalSetSize = true;
+      SetSize(GetImplementation(image).GetNaturalSize());
+      mInternalSetSize = false;
+    }
+  }
 }
 
 void ImageActor::SetStyle( Style style )
@@ -238,7 +268,7 @@ Vector2 ImageActor::GetCurrentImageSize() const
   Vector3 currentSize;
 
   // get the texture size / pixel area if only a subset of it is displayed
-  if (IsPixelAreaSet())
+  if( IsPixelAreaSet() )
   {
     PixelArea area(GetPixelArea());
     return Vector2(area.width, area.height );
@@ -257,7 +287,8 @@ RenderableAttachment& ImageActor::GetRenderableAttachment() const
 
 ImageActor::ImageActor()
 : RenderableActor(),
-  mCustomSizeSet( false ),
+  mUsingNaturalSize(true),
+  mInternalSetSize(false),
   mFadeIn( false ),
   mFadeInitial( true ),
   mLoadedConnection( this ),
@@ -284,10 +315,39 @@ void ImageActor::OnImageSet( Image& image )
   }
 }
 
+void ImageActor::SetNaturalSize( Image& image )
+{
+  if( mUsingNaturalSize )
+  {
+    Vector2 size;
+    if( IsPixelAreaSet() )
+    {
+      PixelArea area(GetPixelArea());
+      size.width = area.width;
+      size.height = area.height;
+    }
+    else
+    {
+      size = image.GetNaturalSize();
+    }
+
+    mInternalSetSize = true;
+    SetSize( size );
+    mInternalSetSize = false;
+  }
+}
+
 void ImageActor::OnSizeSet( const Vector3& targetSize )
 {
-  // True if SizeSet() has ever been called
-  mCustomSizeSet = true;
+  if( !mInternalSetSize )
+  {
+    mUsingNaturalSize = false;
+  }
+}
+
+void ImageActor::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
+{
+  mUsingNaturalSize = false;
 }
 
 void ImageActor::OnStageConnectionInternal()
@@ -315,18 +375,22 @@ void ImageActor::ImageLoaded( Dali::Image image )
   // blank frames during load / reload.
   mImageAttachment->SetImage( &GetImplementation( image ) );
 
-  // If size has never been set
-  if( !mCustomSizeSet )
+  // If size has never been set by application
+  if( mUsingNaturalSize )
   {
     // If a pixel area has been set, use this size
-    if (mImageAttachment->IsPixelAreaSet())
+    if( IsPixelAreaSet() )
     {
-      const PixelArea& area = mImageAttachment->GetPixelArea();
+      const PixelArea& area = GetPixelArea();
+      mInternalSetSize = true;
       SetSize(area.width, area.height);
+      mInternalSetSize = false;
     }
     else
     {
-      SetSize(image.GetWidth(), image.GetHeight());
+      mInternalSetSize = true;
+      SetSize( GetImplementation(image).GetNaturalSize() );
+      mInternalSetSize = false;
     }
   }
 
index 574b232..80b90af 100644 (file)
@@ -81,7 +81,7 @@ public:
   /**
    * Set the image rendered by the actor's attachment.
    * When the image is loaded the actors size will be reset to the image size,
-   * unless a custom size chosen via Actor:SetSize().
+   * unless a custom size is chosen via Actor:SetSize().
    * The old image will continue to be displayed until the new image has loaded
    * @param [in] image A pointer to the image to display or NULL not to display anything.
    */
@@ -94,6 +94,11 @@ public:
   Dali::Image GetImage();
 
   /**
+   * @copydoc Dali::ImageActor::SetToNaturalSize()
+   */
+  void SetToNaturalSize();
+
+  /**
    * Set a region of the image to display, in pixels.
    * @param [in] pixelArea The area of the image to display.
    * This in pixels, relative to the top-left (0,0) of the image.
@@ -240,6 +245,10 @@ private:
   // Helper for overloads of SetImage().
   void OnImageSet( Image& image );
 
+  // Helper to set the actor to the image's natural size
+  void SetNaturalSize( Image& image );
+
+
   /**
    * From Actor.
    * This is called after SizeSet() has been called.
@@ -247,6 +256,11 @@ private:
   virtual void OnSizeSet( const Vector3& targetSize );
 
   /**
+   * @copydoc Actor::OnSizeAnimation( Animation& animation, const Vector3& targetSize )
+   */
+  virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
+
+  /**
    * From Actor; used to trigger fade-in animations.
    */
   virtual void OnStageConnectionInternal();
@@ -273,9 +287,10 @@ private:
   ImageConnector     mImageNext;       ///< Manages the Image this ImageActor will show (used when changing displayed image)
 
   // flags, compressed to bitfield (uses only 4 bytes)
-  bool mCustomSizeSet:1; ///< True if SizeSet() has ever been called
-  bool mFadeIn:1;        ///< True if fade in animation is enabled
-  bool mFadeInitial:1;   ///< True if fading in for the first time
+  bool mUsingNaturalSize:1; ///< True only when the actor is using
+  bool mInternalSetSize:1;  ///< True whilst setting size internally, false at all other times
+  bool mFadeIn:1;           ///< True if fade in animation is enabled
+  bool mFadeInitial:1;      ///< True if fading in for the first time
 
   SlotDelegate<ImageActor> mLoadedConnection; ///< Tracks the connection to the "loading finished" signal
 
index 917a08c..f1ce664 100644 (file)
@@ -263,7 +263,7 @@ void TextActor::SetText(const Dali::Text& text)
   SetText( utfCodes );
 }
 
-void TextActor::SetNaturalSize()
+void TextActor::SetToNaturalSize()
 {
   // ignore size set by application
   mUsingNaturalSize = true;
index 4c78f17..2157170 100644 (file)
@@ -97,9 +97,9 @@ public:
   void SetText(const TextArray& utfCodes);
 
   /**
-   * @copydoc Dali::TextActor::SetNaturalSize()
+   * @copydoc Dali::TextActor::SetToNaturalSize()
    */
-  void SetNaturalSize();
+  void SetToNaturalSize();
 
   /**
    * @copydoc Dali::TextActor::GetFont()
index 5b4f7c6..e61e84e 100644 (file)
@@ -230,6 +230,11 @@ unsigned int Image::GetHeight() const
   }
 }
 
+Vector2 Image::GetNaturalSize() const
+{
+  return Vector2( mWidth, mHeight );
+}
+
 void Image::Connect()
 {
   ++mConnectionCount;
index 42b7e56..23d614e 100644 (file)
@@ -180,6 +180,12 @@ public:
   unsigned int GetHeight() const;
 
   /**
+   * Return the natural size of the image.
+   * This is the size that the loaded image will take
+   */
+  Vector2 GetNaturalSize() const;
+
+  /**
    * @copydoc Dali::Image::GetFilename()
    */
   const std::string& GetFilename() const;
index 7cc5e9f..af4a33f 100644 (file)
@@ -94,6 +94,11 @@ Image ImageActor::GetImage()
   return GetImplementation(*this).GetImage();
 }
 
+void ImageActor::SetToNaturalSize()
+{
+  GetImplementation(*this).SetToNaturalSize();
+}
+
 void ImageActor::SetPixelArea(const PixelArea& pixelArea)
 {
   GetImplementation(*this).SetPixelArea(pixelArea);
index 4cc74d3..57fba3a 100644 (file)
@@ -132,9 +132,9 @@ void TextActor::SetText(const Text& text)
   GetImplementation(*this).SetText(text);
 }
 
-void TextActor::SetNaturalSize()
+void TextActor::SetToNaturalSize()
 {
-  GetImplementation(*this).SetNaturalSize();
+  GetImplementation(*this).SetToNaturalSize();
 }
 
 Font TextActor::GetFont() const