Optimize the graphics loader: don't put the image in the queue if it is directly loadable and no conversion is needed. No more temporary preview image, yeah!

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25166 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2008-06-06 13:30:38 +00:00
parent e4a5278060
commit 896cb74fe2
3 changed files with 40 additions and 11 deletions

View File

@ -41,6 +41,13 @@ public:
///
Impl(FileName const & file);
/**
* If no file conversion is needed, then tryDisplayFormat() calls
* loadImage() directly.
* \return true if a conversion is necessary.
*/
bool tryDisplayFormat(FileName & filename, string & from);
/** Start the image conversion process, checking first that it is
* necessary. If it is necessary, then a conversion task is started.
* CacheItem asumes that the conversion is asynchronous and so
@ -48,9 +55,6 @@ public:
* is finished, this Signal is emitted, returning the converted
* file to this->imageConverted.
*
* If no file conversion is needed, then convertToDisplayFormat() calls
* loadImage() directly.
*
* convertToDisplayFormat() will set the loading status flag as
* approriate through calls to setStatus().
*/
@ -135,6 +139,16 @@ FileName const & CacheItem::filename() const
}
bool CacheItem::tryDisplayFormat() const
{
if (pimpl_->status_ != WaitingToLoad)
pimpl_->reset();
FileName filename;
string from;
return pimpl_->tryDisplayFormat(filename, from);
}
void CacheItem::startLoading() const
{
pimpl_->startLoading();
@ -335,7 +349,7 @@ static string const findTargetFormat(string const & from)
}
void CacheItem::Impl::convertToDisplayFormat()
bool CacheItem::Impl::tryDisplayFormat(FileName & filename, string & from)
{
setStatus(Converting);
@ -345,11 +359,9 @@ void CacheItem::Impl::convertToDisplayFormat()
setStatus(ErrorNoFile);
LYXERR(Debug::GRAPHICS, "\tThe file is not readable");
}
return;
return true;
}
// Make a local copy in case we unzip it
FileName filename;
zipped_ = filename_.isZippedFile();
if (zipped_) {
unzipped_filename_ = FileName::tempName(
@ -357,7 +369,7 @@ void CacheItem::Impl::convertToDisplayFormat()
if (unzipped_filename_.empty()) {
setStatus(ErrorConverting);
LYXERR(Debug::GRAPHICS, "\tCould not create temporary file.");
return;
return true;
}
filename = unzipFile(filename_, unzipped_filename_.toFilesystemEncoding());
} else {
@ -369,7 +381,7 @@ void CacheItem::Impl::convertToDisplayFormat()
<< "\tAttempting to convert image file: " << filename
<< "\n\twith displayed filename: " << to_utf8(displayed_filename));
string const from = formats.getFormatFromFile(filename);
from = formats.getFormatFromFile(filename);
if (from.empty()) {
setStatus(ErrorConverting);
LYXERR(Debug::GRAPHICS, "\tCould not determine file format.");
@ -382,18 +394,29 @@ void CacheItem::Impl::convertToDisplayFormat()
LYXERR(Debug::GRAPHICS, "\tNo conversion needed (from == to)!");
file_to_load_ = filename;
loadImage();
return;
return true;
}
if (ConverterCache::get().inCache(filename, to_)) {
LYXERR(Debug::GRAPHICS, "\tNo conversion needed (file in file cache)!");
file_to_load_ = ConverterCache::get().cacheName(filename, to_);
loadImage();
return;
return true;
}
return false;
}
void CacheItem::Impl::convertToDisplayFormat()
{
LYXERR(Debug::GRAPHICS, "\tConverting it to " << to_ << " format.");
// Make a local copy in case we unzip it
FileName filename;
string from;
if (tryDisplayFormat(filename, from))
return;
// Add some stuff to create a uniquely named temporary file.
// This file is deleted in loadImage after it is loaded into memory.
FileName const to_file_base = FileName::tempName("CacheItem");

View File

@ -53,6 +53,9 @@ public:
///
support::FileName const & filename() const;
/// Try to load a display format.
bool tryDisplayFormat() const;
/// It's in the cache. Now start the loading process.
void startLoading() const;

View File

@ -433,6 +433,9 @@ void Loader::Impl::startLoading()
if (status_ != WaitingToLoad)
return;
if (cached_item_->tryDisplayFormat())
return;
LoaderQueue::get().touch(cached_item_);
}