Dali 3D User Interface Engine
List of all members | Public Member Functions | Private Member Functions | Private Attributes
Dali::Internal::ImageFactory Class Reference

ImageFactory is an object that manages Image resource load requests. More...

#include <image-factory.h>

Inheritance diagram for Dali::Internal::ImageFactory:
Inheritance graph
[legend]
Collaboration diagram for Dali::Internal::ImageFactory:
Collaboration graph
[legend]

Public Member Functions

 ImageFactory (ResourceClient &resourceClient)
 default constructor More...
 
virtual ~ImageFactory ()
 Default destructor. More...
 
ImageFactoryCache::RequestRegisterRequest (const std::string &filename, const ImageAttributes *attributes)
 Registers a request for an image resource if not yet available, but does not start loading yet. More...
 
ResourceTicketPtr Load (ImageFactoryCache::Request &request)
 Issue a request which has already been registered with ImageFactory. More...
 
ResourceTicketPtr Reload (ImageFactoryCache::Request &request)
 Tells ResourceManager to reload image from filesystem. More...
 
void RecoverFromContextLoss ()
 Ensures all filesystem images are reloaded into textures. More...
 
void RegisterForContextRecovery (ContextRecoveryInterface *object)
 Register an object into the context recovery list of the image factory. More...
 
void UnregisterFromContextRecovery (ContextRecoveryInterface *object)
 Unregister an object from the context recovery list of the image factory. More...
 
const std::string & GetRequestPath (const ImageFactoryCache::RequestPtr &request) const
 Get resource path used in request. More...
 
const ImageAttributesGetActualAttributes (const ResourceTicketPtr &ticket) const
 Get ImageAttributes for an already requested image resource. More...
 
const ImageAttributesGetRequestAttributes (const ImageFactoryCache::RequestPtr &request) const
 Get ImageAttributes used for request. More...
 
void GetImageSize (const ImageFactoryCache::RequestPtr &request, const ResourceTicketPtr &ticket, Size &size)
 Retrieve the size of an image. More...
 
void ReleaseTicket (ResourceTicket *ticket)
 Prevents releasing and reloading image resources in the same frame. More...
 
void FlushReleaseQueue ()
 Flush the queue of resource tickets that were about to be relased. More...
 
virtual void RequestDiscarded (const ImageFactoryCache::Request &request)
 Finds request by id in mRequestCache and mUrlCache and removes relevant entries. More...
 

Private Member Functions

 ImageFactory (const ImageFactory &)
 
ImageFactoryoperator= (const ImageFactory &rhs)
 
bool CompareAttributes (const ImageAttributes &requested, const ImageAttributes &actual) const
 Checks if the previously loaded image's attributes are compatible with a new request. More...
 
ImageFactoryCache::RequestInsertNewRequest (ResourceId resourceId, const std::string &url, std::size_t urlHash, const ImageAttributes *attr)
 Inserts a new request to the request cache and url cache. More...
 
ImageFactoryCache::RequestFindRequest (const std::string &filename, size_t hash, const ImageAttributes *attributes)
 Searches request cache for exact match. More...
 
ResourceTicketPtr FindCompatibleResource (const std::string &filename, size_t hash, const ImageAttributes *attributes)
 Searches through tickets to find a compatible resource. More...
 
ResourceTicketPtr IssueLoadRequest (const std::string &filename, const ImageAttributes *attributes)
 Helper function that requests the image resource from platform abstraction. More...
 
std::size_t GetHashForCachedRequest (const ImageFactoryCache::Request &request)
 Looks-up the hash of the string locator of the already-registered Request passed in. More...
 

Private Attributes

ResourceClientmResourceClient
 
ImageFactoryCache::RequestPathHashMap mUrlCache
 A multimap of url hashes and request IDs. More...
 
ImageFactoryCache::RequestIdMap mRequestCache
 A map of request IDs and request information. More...
 
ResourceTicketContainer mTicketsToRelease
 List of ticket handles. More...
 
Vector
< ContextRecoveryInterface * > 
mContextRecoveryList
 List of the objects who needs context recovery. More...
 
float mMaxScale
 Defines maximum size difference between compatible resources. More...
 
ImageFactoryCache::RequestId mReqIdCurrent
 Internal counter for Request IDs. More...
 

Detailed Description

ImageFactory is an object that manages Image resource load requests.

It utilises an internal caching system where previous requests and associated resources are stored to avoid accessing the file system when not necessary.

Definition at line 44 of file image-factory.h.

Constructor & Destructor Documentation

Dali::Internal::ImageFactory::ImageFactory ( ResourceClient resourceClient)

default constructor

Definition at line 46 of file image-factory.cpp.

Dali::Internal::ImageFactory::~ImageFactory ( )
virtual

Default destructor.

Definition at line 53 of file image-factory.cpp.

References mRequestCache.

Dali::Internal::ImageFactory::ImageFactory ( const ImageFactory )
private

Member Function Documentation

bool Dali::Internal::ImageFactory::CompareAttributes ( const ImageAttributes requested,
const ImageAttributes actual 
) const
private

Checks if the previously loaded image's attributes are compatible with a new request.

Parameters
[in]requestedThe requested attributes
[in]actualThe actual attributes
Returns
True if the attributes are compatible

Definition at line 310 of file image-factory.cpp.

References Dali::SamplingMode::DONT_CARE, Dali::Internal::ImageAttributes::GetFilterMode(), Dali::Internal::ImageAttributes::GetHeight(), Dali::Internal::ImageAttributes::GetScalingMode(), Dali::Internal::ImageAttributes::GetWidth(), and mMaxScale.

Referenced by FindCompatibleResource().

Here is the call graph for this function:

Here is the caller graph for this function:

ResourceTicketPtr Dali::Internal::ImageFactory::FindCompatibleResource ( const std::string &  filename,
size_t  hash,
const ImageAttributes attributes 
)
private

Searches through tickets to find a compatible resource.

Parameters
[in]filenameThe url of the image resource.
[in]hashHash value for the filename.
[in]attributesPointer to ImageAttributes used for the request or NULL if default attributes were used.
Returns
A ticket pointer to the found resource or an unitialized pointer if no compatible one is found.

Definition at line 382 of file image-factory.cpp.

References CompareAttributes(), DALI_ASSERT_DEBUG, Dali::Internal::ImageAttributes::DEFAULT_ATTRIBUTES, Dali::IntrusivePtr< T >::Get(), mRequestCache, mResourceClient, mUrlCache, Dali::Internal::ResourceClient::RequestResourceTicket(), Dali::IntrusivePtr< T >::Reset(), Dali::Integration::ResourceBitmap, Dali::Internal::ImageFactoryCache::Request::resourceId, Dali::Integration::ResourceNativeImage, Dali::Integration::ResourceTargetImage, and Dali::Internal::ImageFactoryCache::Request::url.

Referenced by Load().

Here is the call graph for this function:

Here is the caller graph for this function:

Request * Dali::Internal::ImageFactory::FindRequest ( const std::string &  filename,
size_t  hash,
const ImageAttributes attributes 
)
private

Searches request cache for exact match.

Parameters
[in]filenameThe url of the image resource.
[in]hashHash value for the filename.
[in]attributesPointer to ImageAttributes used for the request or NULL if default attributes were used.
Returns
pointer to the found request or NULL if no exact match is found.

Definition at line 333 of file image-factory.cpp.

References Dali::Internal::ImageFactoryCache::Request::attributes, DALI_ASSERT_DEBUG, Dali::Internal::ImageAttributes::DEFAULT_ATTRIBUTES, mRequestCache, mUrlCache, and Dali::Internal::ImageFactoryCache::Request::url.

Referenced by RegisterRequest().

Here is the caller graph for this function:

void Dali::Internal::ImageFactory::FlushReleaseQueue ( )

Flush the queue of resource tickets that were about to be relased.

This discards the kept ticket handles at the end of each frame, and this way prevents releasing and reloading image resources in the same frame.

Definition at line 305 of file image-factory.cpp.

References mTicketsToRelease.

const ImageAttributes & Dali::Internal::ImageFactory::GetActualAttributes ( const ResourceTicketPtr ticket) const

Get ImageAttributes for an already requested image resource.

Precondition
id should mark an existing Resource (Ticket is alive)
Parameters
[in]ticketof the image
Returns
ImageAttributes used for request.
Exceptions
Throwsexception if id is not valid.

Definition at line 255 of file image-factory.cpp.

References DALI_ASSERT_DEBUG, Dali::Internal::ImageAttributes::DEFAULT_ATTRIBUTES, Dali::IntrusivePtr< T >::Get(), Dali::Integration::ResourceBitmap, Dali::Integration::ResourceNativeImage, and Dali::Integration::ResourceTargetImage.

Referenced by Dali::Internal::ResourceImage::GetAttributes(), and GetImageSize().

Here is the call graph for this function:

Here is the caller graph for this function:

std::size_t Dali::Internal::ImageFactory::GetHashForCachedRequest ( const ImageFactoryCache::Request request)
private

Looks-up the hash of the string locator of the already-registered Request passed in.

Parameters
[in]requestThe image load request to return a locator string hash for.
Returns
The hash of the locator string used in the request.

Definition at line 499 of file image-factory.cpp.

References DALI_ASSERT_DEBUG, Dali::Internal::ImageFactoryCache::Request::GetId(), and mUrlCache.

Referenced by Load().

Here is the call graph for this function:

Here is the caller graph for this function:

void Dali::Internal::ImageFactory::GetImageSize ( const ImageFactoryCache::RequestPtr request,
const ResourceTicketPtr ticket,
Size size 
)
const ImageAttributes & Dali::Internal::ImageFactory::GetRequestAttributes ( const ImageFactoryCache::RequestPtr request) const

Get ImageAttributes used for request.

Precondition
req must point to a Request registered with ImageFactory
Parameters
[in]requestof the image
Returns
ImageAttributes used for request.

Definition at line 268 of file image-factory.cpp.

References Dali::Internal::ImageFactoryCache::Request::attributes, and Dali::Internal::ImageAttributes::DEFAULT_ATTRIBUTES.

Referenced by Dali::Internal::ResourceImage::GetAttributes(), and GetImageSize().

Here is the caller graph for this function:

const std::string & Dali::Internal::ImageFactory::GetRequestPath ( const ImageFactoryCache::RequestPtr request) const

Get resource path used in request.

Parameters
[in]requestof the image
Returns
resource path

Definition at line 243 of file image-factory.cpp.

References Dali::Internal::ImageFactoryCache::Request::url.

Referenced by GetImageSize(), and Dali::Internal::ResourceImage::GetUrl().

Here is the caller graph for this function:

Request * Dali::Internal::ImageFactory::InsertNewRequest ( ResourceId  resourceId,
const std::string &  url,
std::size_t  urlHash,
const ImageAttributes attr 
)
private

Inserts a new request to the request cache and url cache.

Note
this method increases the current request Id counter (mReqIdCurrent)
Parameters
[in]resourceIdTicket id to insert.
[in]urlThe requested url to insert.
[in]urlHashCalculated hash value for the url.
[in]attrPointer to the requested attributes, NULL if default values are used.
Returns
pointer to Request

Definition at line 324 of file image-factory.cpp.

References mReqIdCurrent, mRequestCache, and mUrlCache.

Referenced by RegisterRequest().

Here is the caller graph for this function:

ResourceTicketPtr Dali::Internal::ImageFactory::IssueLoadRequest ( const std::string &  filename,
const ImageAttributes attributes 
)
private

Helper function that requests the image resource from platform abstraction.

Parameters
[in]filenameThe url of the image resource.
[in]attributesPointer to ImageAttributes to be used for the request or NULL if default attributes are used.
Returns
intrusive pointer to Ticket

: This is weird and pointless: we introduce a synchronous load of the image header on the event thread here to learn the image's on-disk dimensions to pass on to the resource system, but the default behaviour of the resource system when no dimensions are provided is to use exactly these on-disk dimensions when it eventually does the full load and decode.

Definition at line 450 of file image-factory.cpp.

References Dali::FittingMode::DEFAULT, Dali::SamplingMode::DEFAULT, Dali::Uint16Pair::FromFloatVec2(), Dali::Internal::ImageAttributes::GetFilterMode(), Dali::ResourceImage::GetImageSize(), Dali::Internal::ImageAttributes::GetOrientationCorrection(), Dali::Internal::ImageAttributes::GetScalingMode(), Dali::Internal::ImageAttributes::GetSize(), mResourceClient, and Dali::Internal::ResourceClient::RequestResource().

Referenced by Load(), and Reload().

Here is the call graph for this function:

Here is the caller graph for this function:

ResourceTicketPtr Dali::Internal::ImageFactory::Load ( ImageFactoryCache::Request request)

Issue a request which has already been registered with ImageFactory.

If the associated Ticket is no longer alive ImageFactory issues a resource load request.

Parameters
[in]requestRequest to be loaded.
Returns
intrusive pointer to image ticket. If Load fails, returned pointer is invalid. (!ret)
Note
Always succeeds in normal use.

Definition at line 78 of file image-factory.cpp.

References Dali::Internal::ImageFactoryCache::Request::attributes, DALI_ASSERT_DEBUG, FindCompatibleResource(), GetHashForCachedRequest(), IssueLoadRequest(), mResourceClient, Dali::Internal::ResourceClient::RequestResourceTicket(), Dali::Integration::ResourceBitmap, Dali::Internal::ImageFactoryCache::Request::resourceId, Dali::Integration::ResourceNativeImage, Dali::Integration::ResourceTargetImage, and Dali::Internal::ImageFactoryCache::Request::url.

Referenced by Dali::Internal::ResourceImage::Connect().

Here is the call graph for this function:

Here is the caller graph for this function:

ImageFactory& Dali::Internal::ImageFactory::operator= ( const ImageFactory rhs)
private
void Dali::Internal::ImageFactory::RecoverFromContextLoss ( )

Ensures all filesystem images are reloaded into textures.

This operation uses the originally requested attributes when reloading the image.

Recovering from context loss does not change the number of tickets if the image size has changed on the file system since the last load/reload.

If two different requests mapped to the same resource before, they will still map to the same resource after context regain even if there would be a better fitting texture.

Precondition
requests must be registered with ImageFactory
Note
If an image is still loading, no new load request will be issued.

Definition at line 181 of file image-factory.cpp.

References mContextRecoveryList, mRequestCache, mResourceClient, Dali::Internal::ResourceClient::ReloadResource(), Dali::Internal::ResourceClient::RequestResourceTicket(), Dali::Internal::ImageFactoryCache::Request::resourceId, and Dali::ResourceLoading.

Here is the call graph for this function:

void Dali::Internal::ImageFactory::RegisterForContextRecovery ( ContextRecoveryInterface object)

Register an object into the context recovery list of the image factory.

Thus its RecoverFromContextLoss() function would be called when the Stage regaining context.

Parameters
[in]objectThe object whose RecoverFromContextLoss() function needs to be called to regain the context.

Definition at line 210 of file image-factory.cpp.

References mContextRecoveryList.

Referenced by Dali::Internal::Atlas::AllocateAtlas().

Here is the caller graph for this function:

Request * Dali::Internal::ImageFactory::RegisterRequest ( const std::string &  filename,
const ImageAttributes attributes 
)

Registers a request for an image resource if not yet available, but does not start loading yet.

Use Load( req ) to issue load request. If image was already requested, an existing request is returned.

Parameters
[in]filenamepath of requested image resource
[in]attributespointer to the ImageAttributes of the request. If NULL, default attributes are used.
Returns
request pointer

Definition at line 60 of file image-factory.cpp.

References Dali::CalculateHash(), FindRequest(), and InsertNewRequest().

Here is the call graph for this function:

void Dali::Internal::ImageFactory::ReleaseTicket ( ResourceTicket ticket)

Prevents releasing and reloading image resources in the same frame.

Parameters
[in]ticketthe resource ticket to queue for releasing

Definition at line 299 of file image-factory.cpp.

References mTicketsToRelease.

Referenced by Dali::Internal::ResourceImage::SetTicket(), and Dali::Internal::ResourceImage::~ResourceImage().

Here is the caller graph for this function:

ResourceTicketPtr Dali::Internal::ImageFactory::Reload ( ImageFactoryCache::Request request)

Tells ResourceManager to reload image from filesystem.

Also sends message to render thread. This operation uses the originally requested attributes when reloading the image.

Precondition
req must be registered with ImageFactory
Note
if image is still loading, no new load request will be issued
Parameters
[in]requestRequest to be reloaded.
Returns
the ResourceTicket mapped to the request

Definition at line 119 of file image-factory.cpp.

References Dali::Internal::ImageFactoryCache::Request::attributes, DALI_ASSERT_ALWAYS, DALI_ASSERT_DEBUG, Dali::Internal::ThreadLocalStorage::Get(), Dali::IntrusivePtr< T >::Get(), Dali::Integration::PlatformAbstraction::GetClosestImageSize(), Dali::TizenPlatform::ImageLoader::GetClosestImageSize(), Dali::Internal::ImageAttributes::GetFilterMode(), Dali::Internal::ImageAttributes::GetOrientationCorrection(), Dali::Internal::ThreadLocalStorage::GetPlatformAbstraction(), Dali::Internal::ImageAttributes::GetScalingMode(), Dali::Internal::ImageAttributes::GetSize(), Dali::Uint16Pair::GetX(), Dali::Uint16Pair::GetY(), IssueLoadRequest(), mResourceClient, Dali::Internal::ResourceClient::ReloadResource(), Dali::Internal::ResourceClient::RequestResourceTicket(), Dali::Integration::ResourceBitmap, Dali::Internal::ImageFactoryCache::Request::resourceId, Dali::ResourceLoading, Dali::Integration::ResourceNativeImage, Dali::Integration::ResourceTargetImage, Dali::Internal::ImageFactoryCache::Request::url, and Dali::Vector2::width.

Referenced by Dali::Internal::ResourceImage::Reload().

Here is the call graph for this function:

Here is the caller graph for this function:

void Dali::Internal::ImageFactory::RequestDiscarded ( const ImageFactoryCache::Request request)
virtual

Finds request by id in mRequestCache and mUrlCache and removes relevant entries.

Parameters
[in]idrequest id

Implements Dali::Internal::ImageFactoryCache::RequestLifetimeObserver.

Definition at line 477 of file image-factory.cpp.

References DALI_ASSERT_DEBUG, Dali::Internal::ImageFactoryCache::Request::GetId(), mRequestCache, and mUrlCache.

Here is the call graph for this function:

void Dali::Internal::ImageFactory::UnregisterFromContextRecovery ( ContextRecoveryInterface object)

Unregister an object from the context recovery list of the image factory.

Parameters
[in]objectThe object whose RecoverFromContextLoss() function needs to be called to regain the context.

Definition at line 229 of file image-factory.cpp.

References mContextRecoveryList.

Referenced by Dali::Internal::Atlas::ReleaseAtlas().

Here is the caller graph for this function:

Member Data Documentation

Vector<ContextRecoveryInterface*> Dali::Internal::ImageFactory::mContextRecoveryList
private

List of the objects who needs context recovery.

Definition at line 236 of file image-factory.h.

Referenced by RecoverFromContextLoss(), RegisterForContextRecovery(), and UnregisterFromContextRecovery().

float Dali::Internal::ImageFactory::mMaxScale
private

Defines maximum size difference between compatible resources.

Definition at line 237 of file image-factory.h.

Referenced by CompareAttributes().

ImageFactoryCache::RequestId Dali::Internal::ImageFactory::mReqIdCurrent
private

Internal counter for Request IDs.

Definition at line 238 of file image-factory.h.

Referenced by InsertNewRequest().

ImageFactoryCache::RequestIdMap Dali::Internal::ImageFactory::mRequestCache
private

A map of request IDs and request information.

Definition at line 234 of file image-factory.h.

Referenced by FindCompatibleResource(), FindRequest(), InsertNewRequest(), RecoverFromContextLoss(), RequestDiscarded(), and ~ImageFactory().

ResourceClient& Dali::Internal::ImageFactory::mResourceClient
private
ResourceTicketContainer Dali::Internal::ImageFactory::mTicketsToRelease
private

List of ticket handles.

Definition at line 235 of file image-factory.h.

Referenced by FlushReleaseQueue(), and ReleaseTicket().

ImageFactoryCache::RequestPathHashMap Dali::Internal::ImageFactory::mUrlCache
private

A multimap of url hashes and request IDs.

Definition at line 233 of file image-factory.h.

Referenced by FindCompatibleResource(), FindRequest(), GetHashForCachedRequest(), InsertNewRequest(), and RequestDiscarded().


The documentation for this class was generated from the following files:
Dali Docs Home
Read more about Dali