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()
*/
GetTimeMicrosecondsFunc,
SuspendFunc,
ResumeFunc,
- LoadImageMetadataFunc,
LoadResourceFunc,
SaveResourceFunc,
SaveFileFunc,
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");
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);
}
// 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.
}
/**
- * 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,
// 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
{
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 )
}
} // namespace Internal
-
} // namespace Dali
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() );
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 );
/**
* 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.
* @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
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;
}
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);
}