using namespace std;
-CImageLoader::CImageLoader(const CStdString &path)
+CImageLoader::CImageLoader(const CStdString &path, const bool useCache)
{
m_path = path;
m_texture = NULL;
+ m_use_cache = useCache;
}
CImageLoader::~CImageLoader()
bool CImageLoader::DoWork()
{
bool needsChecking = false;
+ CStdString loadPath;
CStdString texturePath = g_TextureManager.GetTexturePath(m_path);
- CStdString loadPath = CTextureCache::Get().CheckCachedImage(texturePath, true, needsChecking);
+ if (m_use_cache)
+ loadPath = CTextureCache::Get().CheckCachedImage(texturePath, true, needsChecking);
+ else
+ loadPath = texturePath;
- if (loadPath.IsEmpty())
+ if (m_use_cache && loadPath.IsEmpty())
{
// not in our texture cache, so try and load directly and then cache the result
loadPath = CTextureCache::Get().CacheImage(texturePath, &m_texture);
if (m_texture)
return true; // we're done
}
- if (!loadPath.IsEmpty())
+ if (!m_use_cache || !loadPath.IsEmpty())
{
// direct route - load the image
unsigned int start = XbmcThreads::SystemClockMillis();
// if available, increment reference count, and return the image.
// else, add to the queue list if appropriate.
-bool CGUILargeTextureManager::GetImage(const CStdString &path, CTextureArray &texture, bool firstRequest)
+bool CGUILargeTextureManager::GetImage(const CStdString &path, CTextureArray &texture, bool firstRequest, const bool useCache)
{
CSingleLock lock(m_listSection);
for (listIterator it = m_allocated.begin(); it != m_allocated.end(); ++it)
}
if (firstRequest)
- QueueImage(path);
+ QueueImage(path, useCache);
return true;
}
}
// queue the image, and start the background loader if necessary
-void CGUILargeTextureManager::QueueImage(const CStdString &path)
+void CGUILargeTextureManager::QueueImage(const CStdString &path, bool useCache)
{
CSingleLock lock(m_listSection);
for (queueIterator it = m_queued.begin(); it != m_queued.end(); ++it)
// queue the item
CLargeTexture *image = new CLargeTexture(path);
- unsigned int jobID = CJobManager::GetInstance().AddJob(new CImageLoader(path), this, CJob::PRIORITY_NORMAL);
+ unsigned int jobID = CJobManager::GetInstance().AddJob(new CImageLoader(path, useCache), this, CJob::PRIORITY_NORMAL);
m_queued.push_back(make_pair(jobID, image));
}
class CImageLoader : public CJob
{
public:
- CImageLoader(const CStdString &path);
+ CImageLoader(const CStdString &path, const bool useCache);
virtual ~CImageLoader();
/*!
*/
virtual bool DoWork();
+ bool m_use_cache; ///< Whether or not to use any caching with this image
CStdString m_path; ///< path of image to load
CBaseTexture *m_texture; ///< Texture object to load the image into \sa CBaseTexture.
};
\return true if the image exists, else false.
\sa CGUITextureArray and CGUITexture
*/
- bool GetImage(const CStdString &path, CTextureArray &texture, bool firstRequest);
+ bool GetImage(const CStdString &path, CTextureArray &texture, bool firstRequest, bool useCache = true);
/*!
\brief Request a texture to be unloaded.
unsigned int m_timeToDelete;
};
- void QueueImage(const CStdString &path);
+ void QueueImage(const CStdString &path, bool useCache = true);
std::vector< std::pair<unsigned int, CLargeTexture *> > m_queued;
std::vector<CLargeTexture *> m_allocated;
m_crossFadeTime = 1;
}
-void CGUIImage::SetFileName(const CStdString& strFileName, bool setConstant)
+void CGUIImage::SetFileName(const CStdString& strFileName, bool setConstant, const bool useCache)
{
if (setConstant)
m_info.SetLabel(strFileName, "", GetParentID());
+ // Set whether or not to use cache
+ m_texture.SetUseCache(useCache);
+
if (m_crossFadeTime)
{
// set filename on the next texture
virtual void UpdateInfo(const CGUIListItem *item = NULL);
virtual void SetInfo(const CGUIInfoLabel &info);
- virtual void SetFileName(const CStdString& strFileName, bool setConstant = false);
+ virtual void SetFileName(const CStdString& strFileName, bool setConstant = false, const bool useCache = true);
virtual void SetAspectRatio(const CAspectRatio &aspect);
virtual void SetWidth(float width);
virtual void SetHeight(float height);
filename = right.filename;
useLarge = right.useLarge;
diffuseColor = right.diffuseColor;
-
return *this;
}
m_allocateDynamically = false;
m_isAllocated = NO;
m_invalid = true;
+ m_use_cache = true;
}
CGUITextureBase::CGUITextureBase(const CGUITextureBase &right) :
m_diffuseColor = right.m_diffuseColor;
m_allocateDynamically = right.m_allocateDynamically;
+ m_use_cache = right.m_use_cache;
// defaults
m_vertex.SetRect(m_posX, m_posY, m_posX + m_width, m_posY + m_height);
if (m_isAllocated != NORMAL)
{ // use our large image background loader
CTextureArray texture;
- if (g_largeTextureManager.GetImage(m_info.filename, texture, !IsAllocated()))
+ if (g_largeTextureManager.GetImage(m_info.filename, texture, !IsAllocated(), m_use_cache))
{
m_isAllocated = LARGE;
return true;
}
+void CGUITextureBase::SetUseCache(const bool useCache)
+{
+ m_use_cache = useCache;
+}
+
int CGUITextureBase::GetOrientation() const
{
// multiply our orientations
bool SetWidth(float width);
bool SetHeight(float height);
bool SetFileName(const CStdString &filename);
+ void SetUseCache(const bool useCache = true);
bool SetAspectRatio(const CAspectRatio &aspect);
const CStdString& GetFileName() const { return m_info.filename; };
CRect m_vertex; // vertex coords to render
bool m_invalid; // if true, we need to recalculate
-
+ bool m_use_cache;
unsigned char m_alpha;
float m_frameWidth, m_frameHeight; // size in pixels of the actual frame within the texture
sscanf(_colorDiffuse, "%x", &colorDiffuse);
}
- void ControlImage::setImage(const char* imageFilename) throw (UnimplementedException)
+ void ControlImage::setImage(const char* imageFilename, const bool useCache) throw (UnimplementedException)
{
strFileName = imageFilename;
LOCKGUI;
if (pGUIControl)
- ((CGUIImage*)pGUIControl)->SetFileName(strFileName);
+ ((CGUIImage*)pGUIControl)->SetFileName(strFileName, false, useCache);
}
void ControlImage::setColorDiffuse(const char* cColorDiffuse) throw (UnimplementedException)
const char* colorDiffuse = NULL);
/**
- * setImage(filename) -- Changes the image.
+ * setImage(filename, useCache) -- Changes the image.
*
* filename : string - image filename.
+ * useCache : [opt] bool - true/use cache, false/don't use cache
*
* example:
* - self.image.setImage('special://home/scripts/test.png')
*/
- virtual void setImage(const char* imageFilename) throw (UnimplementedException);
+ virtual void setImage(const char* imageFilename, const bool useCache = true) throw (UnimplementedException);
/**
* setColorDiffuse(colorDiffuse) -- Changes the images color.