Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
Loading...
Searching...
No Matches
CTextureCache Class Reference

Texture cache class for handling the caching of images. More...

#include <TextureCache.h>

Inheritance diagram for CTextureCache:
CJobQueue IJobCallback

Public Member Functions

 CTextureCache ()
 
 ~CTextureCache () override
 
void Initialize ()
 Initialize the texture cache.
 
void Deinitialize ()
 Deinitialize the texture cache.
 
std::string CheckCachedImage (const std::string &image, bool &needsRecaching)
 Check whether we already have this image cached.
 
void BackgroundCacheImage (const std::string &image)
 Cache image (if required) using a background job.
 
bool StartCacheImage (const std::string &image)
 Updates the in-process list.
 
std::string CacheImage (const std::string &image, std::unique_ptr< CTexture > *texture=nullptr, CTextureDetails *details=nullptr, unsigned int idealWidth=0, unsigned int idealHeight=0, CAspectRatio::AspectRatio aspectRatio=CAspectRatio::CENTER)
 Cache an image to image cache, optionally return the texture.
 
bool CacheImage (const std::string &image, CTextureDetails &details)
 Cache an image to image cache if not already cached, returning the image details.
 
bool HasCachedImage (const std::string &image)
 Check whether an image is in the cache Note: If the image url won't normally be cached (eg a skin image) this function will return false.
 
void ClearCachedImage (const std::string &image, bool deleteSource=false)
 clear the cached version of the given image
 
bool ClearCachedImage (int textureID)
 clear the cached version of the image with given id
 
bool AddCachedTexture (const std::string &image, const CTextureDetails &details)
 Add this image to the database Thread-safe wrapper of CTextureDatabase::AddCachedTexture.
 
bool Export (const std::string &image, const std::string &destination, bool overwrite)
 Export a (possibly) cached image to a file.
 
bool Export (const std::string &image, const std::string &destination)
 
bool CleanAllUnusedImages ()
 
- Public Member Functions inherited from CJobQueue
 CJobQueue (bool lifo=false, unsigned int jobsAtOnce=1, CJob::PRIORITY priority=CJob::PRIORITY_LOW)
 CJobQueue constructor.
 
 ~CJobQueue () override
 CJobQueue destructor Cancels any in-process jobs, and destroys the job queue.
 
bool AddJob (CJob *job)
 Add a job to the queue On completion of the job, destruction of the job queue or in case the job could not be added successfully, the CJob object will be destroyed.
 
template<typename F >
void Submit (F &&f)
 Add a function f to this job queue.
 
void CancelJob (const CJob *job)
 Cancel a job in the queue Cancels a job in the queue. Any job currently being processed may complete after this call has completed, but OnJobComplete will not be performed. If the job is only queued then it will be removed from the queue and deleted.
 
void CancelJobs ()
 Cancel all jobs in the queue Removes all jobs from the queue. Any job currently being processed may complete after this call has completed, but OnJobComplete will not be performed.
 
bool IsProcessing () const
 Check whether the queue is processing a job.
 
void OnJobAbort (unsigned int jobID, CJob *job) override
 The callback used when a job will be aborted.
 
- Public Member Functions inherited from IJobCallback
virtual ~IJobCallback ()=default
 Destructor for job call back objects.
 
virtual void OnJobProgress (unsigned int jobID, unsigned int progress, unsigned int total, const CJob *job)
 An optional callback function that a job may call while processing.
 

Static Public Member Functions

static std::string GetCacheFile (const std::string &url)
 retrieve a cache file (relative to the cache path) to associate with the given image, excluding extension Use GetCachedPath(GetCacheFile(url)+extension) for the full path to the file.
 
static std::string GetCachedPath (const std::string &file)
 retrieve the full path of the given cached file
 

Additional Inherited Members

- Protected Member Functions inherited from CJobQueue
bool QueueEmpty () const
 Returns if we still have jobs waiting to be processed NOTE: This function does not take into account the jobs that are currently processing.
 

Detailed Description

Texture cache class for handling the caching of images.

Manages the caching of images for use as control textures. Images are cached both as originals (direct copies) and as .dds textures for fast loading. Images may be periodically checked for updates and may be purged from the cache if unused for a set period of time.

Constructor & Destructor Documentation

◆ CTextureCache()

CTextureCache::CTextureCache ( )

◆ ~CTextureCache()

CTextureCache::~CTextureCache ( )
overridedefault

Member Function Documentation

◆ AddCachedTexture()

bool CTextureCache::AddCachedTexture ( const std::string & image,
const CTextureDetails & details )

Add this image to the database Thread-safe wrapper of CTextureDatabase::AddCachedTexture.

Parameters
imageurl of the original image
detailsthe texture details to add
Returns
true if we successfully added to the database, false otherwise.

◆ BackgroundCacheImage()

void CTextureCache::BackgroundCacheImage ( const std::string & image)

Cache image (if required) using a background job.

Checks firstly whether an image is already cached, and return URL if so [see CheckCacheImage] If the image is not yet in the database, a background job is started to cache the image and add to the database [see CTextureCacheJob]

Parameters
imageurl of the image to cache
See also
CacheImage

◆ CacheImage() [1/2]

bool CTextureCache::CacheImage ( const std::string & image,
CTextureDetails & details )

Cache an image to image cache if not already cached, returning the image details.

Parameters
imageurl of the image to cache.
details[out] the image details.
Returns
true if the image is in the cache, false otherwise.
See also
CTextureCacheJob::CacheTexture

◆ CacheImage() [2/2]

std::string CTextureCache::CacheImage ( const std::string & image,
std::unique_ptr< CTexture > * texture = nullptr,
CTextureDetails * details = nullptr,
unsigned int idealWidth = 0,
unsigned int idealHeight = 0,
CAspectRatio::AspectRatio aspectRatio = CAspectRatio::CENTER )

Cache an image to image cache, optionally return the texture.

Caches the given image, returning the texture if the caller wants it.

Parameters
imageurl of the image to cache
texture[out] the loaded image
details[out] details of the cached image
idealWidththe ideal width of the returned texture (defaults to 0, no ideal width). Only matters if texture is not null.
idealHeightthe ideal height of the returned texture (defaults to 0, no ideal height). Only matters if texture is not null.
aspectRatiothe aspect ratio mode of the texture (defaults to "center"). Only matters if texture is not null.
Returns
cached url of this image
See also
CTextureCacheJob::CacheTexture

◆ CheckCachedImage()

std::string CTextureCache::CheckCachedImage ( const std::string & image,
bool & needsRecaching )

Check whether we already have this image cached.

Check and return URL to cached image if it exists; If not, return empty string. If the image is cached, return URL (for original image or .dds version if requested)

Parameters
imageurl of the image to check
needsRecaching[out] whether the image needs recaching.
Returns
cached url of this image
See also
GetCachedImage

◆ CleanAllUnusedImages()

bool CTextureCache::CleanAllUnusedImages ( )
Todo
BACKWARD COMPATIBILITY FOR MUSIC THUMBS

◆ ClearCachedImage() [1/2]

void CTextureCache::ClearCachedImage ( const std::string & image,
bool deleteSource = false )

clear the cached version of the given image

Parameters
imageurl of the image
See also
GetCachedImage
Todo
This can be removed when the texture cache covers everything.

◆ ClearCachedImage() [2/2]

bool CTextureCache::ClearCachedImage ( int textureID)

clear the cached version of the image with given id

Parameters
databaseid of the image
See also
GetCachedImage

◆ Deinitialize()

void CTextureCache::Deinitialize ( )

Deinitialize the texture cache.

◆ Export() [1/2]

bool CTextureCache::Export ( const std::string & image,
const std::string & destination )

◆ Export() [2/2]

bool CTextureCache::Export ( const std::string & image,
const std::string & destination,
bool overwrite )

Export a (possibly) cached image to a file.

Parameters
imageurl of the original image
destinationurl of the destination image, excluding extension.
overwritewhether to overwrite the destination if it exists (TODO: Defaults to false)
Returns
true if we successfully exported the file, false otherwise.

◆ GetCachedPath()

std::string CTextureCache::GetCachedPath ( const std::string & file)
static

retrieve the full path of the given cached file

Parameters
filename of the file
Returns
full path of the cached file

◆ GetCacheFile()

std::string CTextureCache::GetCacheFile ( const std::string & url)
static

retrieve a cache file (relative to the cache path) to associate with the given image, excluding extension Use GetCachedPath(GetCacheFile(url)+extension) for the full path to the file.

Parameters
urllocation of the image
Returns
a "unique" filename for the associated cache file, excluding extension

◆ HasCachedImage()

bool CTextureCache::HasCachedImage ( const std::string & image)

Check whether an image is in the cache Note: If the image url won't normally be cached (eg a skin image) this function will return false.

Parameters
imageurl of the image
Returns
true if the image is cached, false otherwise
See also
ClearCachedImage

◆ Initialize()

void CTextureCache::Initialize ( )

Initialize the texture cache.

◆ StartCacheImage()

bool CTextureCache::StartCacheImage ( const std::string & image)

Updates the in-process list.

Inserts the image url into the currently processing list to avoid 2 jobs being processed at once

Parameters
imageurl of the image to start processing
Returns
true if list updated, false otherwise
See also
CacheImage

The documentation for this class was generated from the following files: