Permalink
Browse files

Add support for caching textures in a job directly from a texture object

  • Loading branch information...
1 parent 06994d1 commit d21ee4aa5f5554b0dd0bee8f9a267cfb992e2872 Jonathan Marshall committed Mar 30, 2012
Showing with 37 additions and 5 deletions.
  1. +5 −0 xbmc/TextureCache.cpp
  2. +3 −0 xbmc/TextureCache.h
  3. +23 −5 xbmc/TextureCacheJob.cpp
  4. +6 −0 xbmc/TextureCacheJob.h
View
@@ -151,6 +151,11 @@ void CTextureCache::BackgroundCacheImage(const CStdString &url)
AddJob(new CTextureCacheJob(url, cacheHash));
}
+void CTextureCache::BackgroundCacheTexture(const CStdString &url, const CBaseTexture *texture, unsigned int max_width, unsigned int max_height)
+{
+ AddJob(new CTextureCacheJob(url, texture, max_width, max_height));
+}
+
CStdString CTextureCache::CacheImageFile(const CStdString &url)
{
// Cache image so that the texture manager can load it.
View
@@ -25,6 +25,8 @@
#include "utils/JobManager.h"
#include "TextureDatabase.h"
+class CBaseTexture;
+
/*!
\ingroup textures
\brief Texture cache class for handling the caching of images.
@@ -86,6 +88,7 @@ class CTextureCache : public CJobQueue
\sa CheckAndCacheImage
*/
void BackgroundCacheImage(const CStdString &image);
+ void BackgroundCacheTexture(const CStdString &image, const CBaseTexture *texture, unsigned int max_width, unsigned int max_height);
/*! \brief Take image URL and add it to image cache
View
@@ -39,6 +39,25 @@ CTextureCacheJob::CTextureCacheJob(const CStdString &url, const CStdString &oldH
m_url = url;
m_oldHash = oldHash;
m_relativeCacheFile = CTextureCache::GetCacheFile(m_url);
+ m_texture = NULL;
+ m_maxWidth = m_maxHeight = 0;
+}
+
+CTextureCacheJob::CTextureCacheJob(const CStdString &url, const CBaseTexture *texture, unsigned int max_width, unsigned int max_height)
+{
+ m_url = url;
+ if (texture)
+ m_texture = new CTexture(*(CTexture *)texture);
+ else
+ m_texture = NULL;
+ m_maxWidth = max_width;
+ m_maxHeight = max_height;
+ m_relativeCacheFile = CTextureCache::GetCacheFile(m_url);
+}
+
+CTextureCacheJob::~CTextureCacheJob()
+{
+ delete m_texture;
}
bool CTextureCacheJob::operator==(const CJob* job) const
@@ -66,8 +85,9 @@ bool CTextureCacheJob::DoWork()
else if (m_hash == m_oldHash)
return true;
- CBaseTexture *texture = LoadImage(image, width, height, flipped);
- if (texture)
+ if (!m_texture)
+ m_texture = LoadImage(image, width, height, flipped);
+ if (m_texture)
{
if (width > 0 && height > 0)
CLog::Log(LOGDEBUG, "%s image '%s' at %dx%d with orientation %d as '%s'", m_oldHash.IsEmpty() ? "Caching" : "Recaching", image.c_str(),
@@ -76,9 +96,7 @@ bool CTextureCacheJob::DoWork()
CLog::Log(LOGDEBUG, "%s image '%s' fullsize with orientation %d as '%s'", m_oldHash.IsEmpty() ? "Caching" : "Recaching", image.c_str(),
texture->GetOrientation(), m_relativeCacheFile.c_str());
- bool success = CPicture::CacheTexture(texture, width, height, CTextureCache::GetCachedPath(m_relativeCacheFile));
- delete texture;
- return success;
+ return CPicture::CacheTexture(m_texture, width, height, CTextureCache::GetCachedPath(m_relativeCacheFile));
}
return false;
}
View
@@ -36,6 +36,8 @@ class CTextureCacheJob : public CJob
{
public:
CTextureCacheJob(const CStdString &url, const CStdString &oldHash);
+ CTextureCacheJob(const CStdString &url, const CBaseTexture *texture, unsigned int max_width, unsigned int max_height);
+ virtual ~CTextureCacheJob();
virtual const char* GetType() const { return "cacheimage"; };
virtual bool operator==(const CJob *job) const;
@@ -74,6 +76,10 @@ class CTextureCacheJob : public CJob
\return a hash string for this image
*/
static CStdString GetImageHash(const CStdString &url);
+
+ unsigned int m_maxWidth;
+ unsigned int m_maxHeight;
+ CBaseTexture *m_texture;
};
/* \brief Job class for creating .dds versions of textures

0 comments on commit d21ee4a

Please sign in to comment.