// 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) { CSingleLock lock(m_listSection); if (path == "image://http%3a%2f%2fcf2.imgobject.com%2ft%2fp%2foriginal%2frXhuBgQyRKB7cW5BRImyVkO89K7.jpg/") { int a = 0; } for (listIterator it = m_allocated.begin(); it != m_allocated.end(); ++it) { CLargeTexture *image = *it; if (image->GetPath() == path) { if (firstRequest) image->AddRef(); texture = image->GetTexture(); return texture.size() > 0; } } if (firstRequest) QueueImage(path); return true; }
// queue the image, and start the background loader if necessary void CGUILargeTextureManager::QueueImage(const std::string &path, bool useCache) { CSingleLock lock(m_listSection); for (queueIterator it = m_queued.begin(); it != m_queued.end(); ++it) { CLargeTexture *image = it->second; if (image->GetPath() == path) { image->AddRef(); return; // already queued } } // queue the item CLargeTexture *image = new CLargeTexture(path); unsigned int jobID = CJobManager::GetInstance().AddJob(new CImageLoader(path, useCache), this, CJob::PRIORITY_NORMAL); m_queued.push_back(std::make_pair(jobID, image)); }
// queue the image, and start the background loader if necessary void CGUILargeTextureManager::QueueImage(const CStdString &path) { CSingleLock lock(m_listSection); for (queueIterator it = m_queued.begin(); it != m_queued.end(); ++it) { CLargeTexture *image = it->second; if (image->GetPath() == path) { image->AddRef(); return; // already queued } } // queue the item #if defined(__VIDONME_MEDIACENTER__) if (!m_queImageLoaders.empty()) { std::deque<std::pair<CImageLoader*, int> >::iterator iter = m_queImageLoaders.begin(); for (; iter != m_queImageLoaders.end(); ++iter) { if ((*iter).first->m_path == path) { (*iter).second++; return; } } } if (!m_queued.empty()) { m_queImageLoaders.push_back(std::make_pair(new CImageLoader(path), 1)); } else { CLargeTexture *image = new CLargeTexture(path); unsigned int jobID = CJobManager::GetInstance().AddJob(new CImageLoader(path), this, CJob::PRIORITY_NORMAL); m_queued.push_back(make_pair(jobID, image)); } #else CLargeTexture *image = new CLargeTexture(path); unsigned int jobID = CJobManager::GetInstance().AddJob(new CImageLoader(path), this, CJob::PRIORITY_NORMAL); m_queued.push_back(make_pair(jobID, image)); #endif }
// if available, increment reference count, and return the image. // else, add to the queue list if appropriate. bool CGUILargeTextureManager::GetImage(const std::string &path, CTextureArray &texture, bool firstRequest, const bool useCache) { CSingleLock lock(m_listSection); for (listIterator it = m_allocated.begin(); it != m_allocated.end(); ++it) { CLargeTexture *image = *it; if (image->GetPath() == path) { if (firstRequest) image->AddRef(); texture = image->GetTexture(); return texture.size() > 0; } } if (firstRequest) QueueImage(path, useCache); return true; }
void CGUILargeTextureManager::OnJobComplete(unsigned int jobID, bool success, CJob *job) { // see if we still have this job id CSingleLock lock(m_listSection); for (queueIterator it = m_queued.begin(); it != m_queued.end(); ++it) { if (it->first == jobID) { // found our job CImageLoader *loader = (CImageLoader *)job; CLargeTexture *image = it->second; image->SetTexture(loader->m_texture); loader->m_texture = NULL; // we want to keep the texture, and jobs are auto-deleted. m_queued.erase(it); m_allocated.push_back(image); #if defined(__VIDONME_MEDIACENTER__) break; #else return; #endif } } #if defined(__VIDONME_MEDIACENTER__) if (!m_queImageLoaders.empty()) { typedef std::pair<CImageLoader*, int> LoaderPair; LoaderPair loaderPair = *m_queImageLoaders.begin(); unsigned int jobID = CJobManager::GetInstance().AddJob(loaderPair.first, this, CJob::PRIORITY_NORMAL); CLargeTexture *image = new CLargeTexture(loaderPair.first->m_path); while (loaderPair.second-- > 1) { image->AddRef(); } m_queued.push_back(make_pair(jobID, image)); m_queImageLoaders.pop_front(); } #endif }
// 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) { // note: max size to load images: 2048x1024? (8MB) CSingleLock lock(m_listSection); for (listIterator it = m_allocated.begin(); it != m_allocated.end(); ++it) { CLargeTexture *image = *it; if (image->GetPath() == path) { if (firstRequest) image->AddRef(); texture = image->GetTexture(); return texture.size() > 0; } } if (firstRequest) QueueImage(path); return true; }