From abded5e44353de2da80f1061f37e6b681f02f099 Mon Sep 17 00:00:00 2001 From: Jonathan Marshall Date: Sat, 26 May 2012 15:48:03 +1200 Subject: [PATCH] factor out OnCachingComplete from OnJobComplete - we shouldn't really be calling OnJobComplete on a job not in the queue --- xbmc/TextureCache.cpp | 46 ++++++++++++++++++++++--------------------- xbmc/TextureCache.h | 8 ++++++++ 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/xbmc/TextureCache.cpp b/xbmc/TextureCache.cpp index ab04ea8ced..9d63405039 100644 --- a/xbmc/TextureCache.cpp +++ b/xbmc/TextureCache.cpp @@ -172,7 +172,7 @@ CStdString CTextureCache::CacheImage(const CStdString &image, CBaseTexture **tex // cache the texture directly CTextureCacheJob job(url); bool success = job.CacheTexture(texture); - OnJobComplete(0, success, &job); + OnCachingComplete(success, &job); return success ? GetCachedPath(job.m_details.file) : ""; } lock.Leave(); @@ -258,32 +258,34 @@ CStdString CTextureCache::GetCachedPath(const CStdString &file) return URIUtils::AddFileToFolder(g_settings.GetThumbnailsFolder(), file); } -void CTextureCache::OnJobComplete(unsigned int jobID, bool success, CJob *job) +void CTextureCache::OnCachingComplete(bool success, CTextureCacheJob *job) { - if (strcmp(job->GetType(), "cacheimage") == 0) + if (success) { - CTextureCacheJob *cacheJob = (CTextureCacheJob *)job; - if (success) - { - if (cacheJob->m_oldHash == cacheJob->m_details.hash) - SetCachedTextureValid(cacheJob->m_url, cacheJob->m_details.updateable); - else - AddCachedTexture(cacheJob->m_url, cacheJob->m_details); - } + if (job->m_oldHash == job->m_details.hash) + SetCachedTextureValid(job->m_url, job->m_details.updateable); + else + AddCachedTexture(job->m_url, job->m_details); + } - { // remove from our processing list - CSingleLock lock(m_processingSection); - std::set::iterator i = m_processing.find(cacheJob->m_url); - if (i != m_processing.end()) - m_processing.erase(i); - } + { // remove from our processing list + CSingleLock lock(m_processingSection); + std::set::iterator i = m_processing.find(job->m_url); + if (i != m_processing.end()) + m_processing.erase(i); + } - m_completeEvent.Set(); + m_completeEvent.Set(); - // TODO: call back to the UI indicating that it can update it's image... - if (success && g_advancedSettings.m_useDDSFanart && !cacheJob->m_details.file.empty()) - AddJob(new CTextureDDSJob(GetCachedPath(cacheJob->m_details.file))); - } + // TODO: call back to the UI indicating that it can update it's image... + if (success && g_advancedSettings.m_useDDSFanart && !job->m_details.file.empty()) + AddJob(new CTextureDDSJob(GetCachedPath(job->m_details.file))); +} + +void CTextureCache::OnJobComplete(unsigned int jobID, bool success, CJob *job) +{ + if (strcmp(job->GetType(), "cacheimage") == 0) + OnCachingComplete(success, (CTextureCacheJob *)job); return CJobQueue::OnJobComplete(jobID, success, job); } diff --git a/xbmc/TextureCache.h b/xbmc/TextureCache.h index 0ccb78956f..22a51be273 100644 --- a/xbmc/TextureCache.h +++ b/xbmc/TextureCache.h @@ -203,6 +203,14 @@ class CTextureCache : public CJobQueue virtual void OnJobComplete(unsigned int jobID, bool success, CJob *job); virtual void OnJobProgress(unsigned int jobID, unsigned int progress, unsigned int total, const CJob *job); + /*! \brief Called when a caching job has completed. + Removes the job from our processing list, updates the database + and fires a DDS job if appropriate. + \param success whether the job was successful. + \param job the caching job. + */ + void OnCachingComplete(bool success, CTextureCacheJob *job); + CCriticalSection m_databaseSection; CTextureDatabase m_database; std::set m_processing; ///< currently processing list to avoid 2 jobs being processed at once