Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
|
Texture cache class for handling the caching of images. More...
#include <TextureCache.h>
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. | |
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.
CTextureCache::CTextureCache | ( | ) |
|
overridedefault |
bool CTextureCache::AddCachedTexture | ( | const std::string & | image, |
const CTextureDetails & | details ) |
Add this image to the database Thread-safe wrapper of CTextureDatabase::AddCachedTexture.
image | url of the original image |
details | the texture details to add |
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]
image | url of the image to cache |
bool CTextureCache::CacheImage | ( | const std::string & | image, |
CTextureDetails & | details ) |
Cache an image to image cache if not already cached, returning the image details.
image | url of the image to cache. |
details | [out] the image details. |
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.
image | url of the image to cache |
texture | [out] the loaded image |
details | [out] details of the cached image |
idealWidth | the ideal width of the returned texture (defaults to 0, no ideal width). Only matters if texture is not null. |
idealHeight | the ideal height of the returned texture (defaults to 0, no ideal height). Only matters if texture is not null. |
aspectRatio | the aspect ratio mode of the texture (defaults to "center"). Only matters if texture is not null. |
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)
image | url of the image to check |
needsRecaching | [out] whether the image needs recaching. |
clear the cached version of the given image
image | url of the image |
clear the cached version of the image with given id
database | id of the image |
void CTextureCache::Deinitialize | ( | ) |
Deinitialize the texture cache.
bool CTextureCache::Export | ( | const std::string & | image, |
const std::string & | destination ) |
bool CTextureCache::Export | ( | const std::string & | image, |
const std::string & | destination, | ||
bool | overwrite ) |
Export a (possibly) cached image to a file.
image | url of the original image |
destination | url of the destination image, excluding extension. |
overwrite | whether to overwrite the destination if it exists (TODO: Defaults to false) |
|
static |
retrieve the full path of the given cached file
file | name of the file |
|
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.
url | location of the image |
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.
image | url of the image |
void CTextureCache::Initialize | ( | ) |
Initialize the texture cache.
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
image | url of the image to start processing |