(ImageLoader) Added synchronous method to get closest image size
authorDavid Steele <david.steele@partner.samsung.com>
Wed, 19 Feb 2014 20:43:47 +0000 (20:43 +0000)
committerPaul Wisbey <p.wisbey@samsung.com>
Mon, 3 Mar 2014 18:34:53 +0000 (18:34 +0000)
[Issue#]       N/A
[Problem]      Can't synchronously determine what the loaded image size will be
[Cause]        Not implemented
[Solution]     Added a new method to the platform abstraction to get the closest
size for a given requested size and orientation correction.
Changed image implementation to set the correct image size on creation.

Change-Id: I7dab185ecc18e6f8605a3c3996d6586c47e5fb6e
[Verification] Build Repo
Signed-off-by: David Steele <david.steele@partner.samsung.com>
automated-tests/dali-test-suite-utils/test-platform-abstraction.h
automated-tests/dali-test-suite/images/utc-Dali-Image.cpp
dali/integration-api/platform-abstraction.h
dali/integration-api/resource-request.h
dali/internal/event/images/encoded-buffer-image-impl.cpp
dali/internal/event/images/image-factory.cpp
dali/internal/event/images/image-impl.cpp
dali/internal/event/images/image-impl.h
dali/public-api/images/image.cpp

index d636ab4..fe01399 100644 (file)
@@ -113,16 +113,23 @@ public:
     mTrace.PushCall("Resume", "");
   }
 
-  /**
-   * @copydoc PlatformAbstraction::LoadImageMetadata()
-   */
-  virtual void LoadImageMetadata(const std::string fileName, Vector2 &size)
+  virtual void GetClosestImageSize( const std::string& filename,
+                                    const ImageAttributes& attributes,
+                                    Vector2& closestSize)
   {
-    size = mSize;
+    closestSize = mSize;
+    mTrace.PushCall("GetClosestImageSize", "");
+  }
 
-    mTrace.PushCall("LoadImageMetadata", "");
+  virtual void GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
+                                    const ImageAttributes& attributes,
+                                    Vector2& closestSize)
+  {
+    closestSize = mSize;
+    mTrace.PushCall("GetClosestImageSize", "");
   }
 
+
   /**
    * @copydoc PlatformAbstraction::LoadResource()
    */
@@ -476,7 +483,6 @@ public: // TEST FUNCTIONS
     GetTimeMicrosecondsFunc,
     SuspendFunc,
     ResumeFunc,
-    LoadImageMetadataFunc,
     LoadResourceFunc,
     SaveResourceFunc,
     SaveFileFunc,
@@ -538,7 +544,6 @@ public: // TEST FUNCTIONS
       case GetTimeMicrosecondsFunc:             return mTrace.FindMethod("GetTimeMicroseconds");
       case SuspendFunc:                         return mTrace.FindMethod("Suspend");
       case ResumeFunc:                          return mTrace.FindMethod("Resume");
-      case LoadImageMetadataFunc:               return mTrace.FindMethod("LoadImageMetadata");
       case LoadResourceFunc:                    return mTrace.FindMethod("LoadResource");
       case SaveResourceFunc:                    return mTrace.FindMethod("SaveResource");
       case LoadFileFunc:                        return mTrace.FindMethod("LoadFile");
index 4576cfe..0053f5c 100644 (file)
@@ -754,7 +754,7 @@ static void UtcDaliImageGetImageSize()
 
   Vector2 size = Image::GetImageSize(gTestImageFilename);
 
-  DALI_TEST_CHECK( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadImageMetadataFunc) );
+  DALI_TEST_CHECK( application.GetPlatform().GetTrace().FindMethod("GetClosestImageSize"));
   DALI_TEST_EQUALS( size, testSize, TEST_LOCATION);
 }
 
index c345cd2..ed05512 100644 (file)
@@ -77,12 +77,30 @@ public:
   // Resource Loading
 
   /**
-   * Load metadata from an image on the native filesystem. This is a synchronous request.
-   * This function is used when the size of an image needs to be determined before it has loaded.
-   * @param[in] filename name of the string to load.
-   * @param[out] size Size of the image.
+   * Determine the size of an image the resource loaders will provide when given the same
+   * image attributes.
+   * This is a synchronous request.
+   * This function is used to determine the size of an image before it has loaded.
+   * @param[in] filename name of the image.
+   * @param[in] attributes The attributes used to load the image
+   * @param[out] closestSize Size of the image that will be loaded.
    */
-  virtual void LoadImageMetadata(const std::string filename, Vector2 &size) = 0;
+  virtual void GetClosestImageSize( const std::string& filename,
+                                    const ImageAttributes& attributes,
+                                    Vector2& closestSize ) = 0;
+
+  /**
+   * Determine the size of an image the resource loaders will provide when given the same
+   * image attributes.
+   * This is a synchronous request.
+   * This function is used to determine the size of an image before it has loaded.
+   * @param[in] resourceBuffer A pointer to an encoded image buffer
+   * @param[in] attributes The attributes used to load the image
+   * @param[out] closestSize Size of the image that will be loaded.
+   */
+  virtual void GetClosestImageSize( ResourcePointer resourceBuffer,
+                                    const ImageAttributes& attributes,
+                                    Vector2& closestSize ) = 0;
 
   /**
    * Request a resource from the native filesystem. This is an asynchronous request.
index fe2950e..8fffcc4 100644 (file)
@@ -77,12 +77,12 @@ public:
   }
 
   /**
-   * Used to save a resource in the native filesystem.
+   * Used to request or save a resource from/to the native filesystem.
    * @param[in] newId         A unique ID for this request.
-   * @param[in] resourceType  The type of resource to save.
-   * @param[in] resourcePath  The location where the resource should be saved.
-   * @param[in] resourcePtr   The resource itself.
-   * @param[in] savePriority  The priority of the save request.
+   * @param[in] resourceType  The type of resource.
+   * @param[in] resourcePath  The location of the resource / where the resource should be saved.
+   * @param[in] resourcePtr   The resource to decode / save.
+   * @param[in] savePriority  The priority of the request.
    */
   ResourceRequest(ResourceId newId,
                   const ResourceType& resourceType,
index 0434b59..42cfa52 100644 (file)
@@ -20,6 +20,7 @@
 // INTERNAL INCLUDES
 #include <dali/internal/event/common/thread-local-storage.h>
 #include <dali/internal/event/resources/resource-client.h>
+#include <dali/integration-api/platform-abstraction.h>
 
 namespace Dali
 {
@@ -50,6 +51,13 @@ Dali::EncodedBufferImage EncodedBufferImage::New( const uint8_t * const encodedI
   DALI_ASSERT_ALWAYS( buffer->GetVector().Size() >= encodedImageByteCount );
 
   memcpy( &(buffer->GetVector()[0]), encodedImage, encodedImageByteCount );
+
+  // Get image size from buffer
+  Vector2 size;
+  Internal::ThreadLocalStorage::Get().GetPlatformAbstraction().GetClosestImageSize( buffer, attributes, size );
+  image->mWidth = (unsigned int) size.width;
+  image->mHeight = (unsigned int) size.height;
+
   ResourceClient &resourceClient = ThreadLocalStorage::Get().GetResourceClient();
   ResourceTicketPtr ticket = resourceClient.DecodeResource( resourceType, buffer );
   if( ticket )
@@ -65,5 +73,4 @@ Dali::EncodedBufferImage EncodedBufferImage::New( const uint8_t * const encodedI
 }
 
 } // namespace Internal
-
 } // namespace Dali
index 15d63e8..393f633 100644 (file)
@@ -161,10 +161,11 @@ ResourceTicketPtr ImageFactory::Reload( Request* request )
       return ticket;
     }
 
-    /// @todo should obtain all attributes information from filesystem and check for compatibility (additional change in PlatformAbstraction)
     Vector2 size;
-    Internal::ThreadLocalStorage::Get().GetPlatformAbstraction().LoadImageMetadata( request->url, size );
+    Internal::ThreadLocalStorage::Get().GetPlatformAbstraction().GetClosestImageSize( request->url, *request->attributes, size );
+
     const ImageAttributes& attrib = static_cast<ImageTicket*>(ticket.Get())->GetAttributes();
+
     if( size == attrib.GetSize() )
     {
       mResourceClient.ReloadResource( ticket->GetId() );
index 71405e6..5b4f7c6 100644 (file)
@@ -51,68 +51,29 @@ Image* Image::New()
   return new Image;
 }
 
-Image* Image::New( const std::string& filename, LoadPolicy loadPol, ReleasePolicy releasePol )
-{
-  Image* image = new Image( loadPol, releasePol );
-
-  image->mRequest = image->mImageFactory.RegisterRequest( filename, NULL );
-
-  if( ! filename.empty() )
-  {
-    Vector2 size;
-    Internal::ThreadLocalStorage::Get().GetPlatformAbstraction().LoadImageMetadata( filename, size );
-    image->mWidth = (int)size.width;
-    image->mHeight = (int)size.height;
-  }
-
-  if( Dali::Image::OnDemand == loadPol )
-  {
-    // load image on demand,
-    // ask for ticket on connect
-  }
-  else
-  {
-    // load image immediately
-    image->mTicket = image->mImageFactory.Load( image->mRequest.Get() );
-    image->mTicket->AddObserver( *image );
-  }
-
-  DALI_LOG_SET_OBJECT_STRING( image, filename );
-
-  return image;
-}
-
 Image* Image::New( const std::string& filename, const Dali::ImageAttributes& attributes, LoadPolicy loadPol, ReleasePolicy releasePol )
 {
   Image* image = new Image( loadPol, releasePol );
 
   if( ! filename.empty() )
   {
-    if( attributes.GetWidth() == 0 && attributes.GetHeight() == 0 )
-    {
-      // Only get actual file size if a requested size is not present.
-      Vector2 size;
-      Internal::ThreadLocalStorage::Get().GetPlatformAbstraction().LoadImageMetadata( filename, size );
-      image->mWidth = (int)size.width;
-      image->mHeight = (int)size.height;
-    }
-    // @TODO: else, determine closest size to requested size
+    Vector2 closestSize;
+
+    Internal::ThreadLocalStorage::Get().GetPlatformAbstraction().GetClosestImageSize( filename, attributes, closestSize );
+    image->mWidth = closestSize.width;
+    image->mHeight = closestSize.height;
   }
 
   image->mRequest = image->mImageFactory.RegisterRequest( filename, &attributes );
 
-  // Lazily load image data later, only when it is needed to draw something:
-  if( Dali::Image::OnDemand == loadPol )
-  {
-    // Ask for ticket later, only on connect.
-  }
-  else
+  if( Dali::Image::Immediate == loadPol )
   {
-    // Trigger loading of the image over on a resource thread eagerly as soon as it
+    // Trigger loading of the image on a seperate resource thread as soon as it
     // can be scheduled:
     image->mTicket = image->mImageFactory.Load( image->mRequest.Get() );
     image->mTicket->AddObserver( *image );
   }
+  // else lazily load image data later, only when it is needed to draw something:
 
   DALI_LOG_SET_OBJECT_STRING( image, filename );
 
index 7665f79..42b7e56 100644 (file)
@@ -77,18 +77,6 @@ public:
   /**
    * Creates object and loads image from filesystem
    * the maximum size of the image is limited by GL_MAX_TEXTURE_SIZE
-   * @param [in] filename the path of the image on the filesystem
-   * @param [in] loadPol controls time of loading a resource from the filesystem (default: load when Image is created).
-   * @param [in] releasePol optionally relase memory when image is not visible on screen (default: keep image data until Image object is alive).
-   * @return a pointer to a newly created object.
-   */
-  static Image* New(const std::string& filename,
-                    LoadPolicy loadPol=ImageLoadPolicyDefault,
-                    ReleasePolicy releasePol=ImageReleasePolicyDefault);
-
-  /**
-   * Creates object and loads image from filesystem
-   * the maximum size of the image is limited by GL_MAX_TEXTURE_SIZE
    * @param [in] filename   the path of the image on the filesystem
    * @param [in] attributes requested parameters for loading (size, cropping etc.)
    *                        if width or height is specified as 0, the natural size will be used.
@@ -97,10 +85,14 @@ public:
    * @return a pointer to a newly created object.
    */
   static Image* New(const std::string& filename,
-                    const Dali::ImageAttributes& attributes,
+                    const Dali::ImageAttributes& attributes=Dali::ImageAttributes::DEFAULT_ATTRIBUTES,
                     LoadPolicy loadPol=ImageLoadPolicyDefault,
                     ReleasePolicy releasePol=ImageReleasePolicyDefault);
 
+
+
+public:
+
   /**
    * Creates object with already loaded NativeImage
    * the maximum size of the image is limited by GL_MAX_TEXTURE_SIZE
index f392f51..b79d1dc 100644 (file)
@@ -33,8 +33,7 @@ const char* const Image::SIGNAL_IMAGE_UPLOADED = "uploaded";
 Vector2 Image::GetImageSize(const std::string fileName)
 {
   Vector2 size;
-  Internal::ThreadLocalStorage::Get().GetPlatformAbstraction().LoadImageMetadata(fileName, size);
-
+  Internal::ThreadLocalStorage::Get().GetPlatformAbstraction().GetClosestImageSize(fileName, ImageAttributes::DEFAULT_ATTRIBUTES, size);
   return size;
 }
 
@@ -58,7 +57,9 @@ Image Image::New(const std::string& filename)
 
 Image Image::New(const std::string& filename, LoadPolicy loadPol, ReleasePolicy releasePol)
 {
-  Internal::Image* internal = Internal::Image::New(filename, loadPol, releasePol);
+  Internal::Image* internal = Internal::Image::New(filename,
+                                                   Dali::ImageAttributes::DEFAULT_ATTRIBUTES,
+                                                   loadPol, releasePol);
   return Image(internal);
 }