remove max previewimage memory usage
This commit is contained in:
parent
582abc333f
commit
4aed15f7a4
@ -19,38 +19,25 @@ struct Renderer
|
|||||||
double scaleX;
|
double scaleX;
|
||||||
double scaleY;
|
double scaleY;
|
||||||
QHash<QString, Poppler::Document *> documentcache;
|
QHash<QString, Poppler::Document *> documentcache;
|
||||||
qsizetype maxTotalPreviewImageMemUsage;
|
|
||||||
std::atomic<qsizetype> currentTotalPreviewImageMemUsage { 0 };
|
|
||||||
QVector<QString> wordsToHighlight;
|
QVector<QString> wordsToHighlight;
|
||||||
Renderer(double scaleX, double scaleY, qsizetype maxPreviewImageMemUsage, QVector<QString> wordsToHighlight)
|
Renderer(double scaleX, double scaleY, QVector<QString> wordsToHighlight)
|
||||||
{
|
{
|
||||||
this->scaleX = scaleX;
|
this->scaleX = scaleX;
|
||||||
this->scaleY = scaleY;
|
this->scaleY = scaleY;
|
||||||
this->maxTotalPreviewImageMemUsage = maxPreviewImageMemUsage;
|
|
||||||
this->wordsToHighlight = wordsToHighlight;
|
this->wordsToHighlight = wordsToHighlight;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*we need this one because std::atomic has none, but this is only a functor for
|
|
||||||
concurrentmap, thus, it's ok for it to be half-broken*/
|
|
||||||
Renderer(const Renderer &o)
|
|
||||||
{
|
|
||||||
this->scaleX = o.scaleX;
|
|
||||||
this->scaleY = o.scaleY;
|
|
||||||
this->maxTotalPreviewImageMemUsage = o.maxTotalPreviewImageMemUsage;
|
|
||||||
this->wordsToHighlight = o.wordsToHighlight;
|
|
||||||
}
|
|
||||||
|
|
||||||
~Renderer()
|
~Renderer()
|
||||||
{
|
{
|
||||||
qDeleteAll(documentcache);
|
qDeleteAll(documentcache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Poppler::Document *document(QString path)
|
Poppler::Document *document(QString path)
|
||||||
{
|
{
|
||||||
if(documentcache.contains(path))
|
if(documentcache.contains(path))
|
||||||
|
{
|
||||||
return documentcache.value(path);
|
return documentcache.value(path);
|
||||||
|
}
|
||||||
Poppler::Document *result = Poppler::Document::load(path);
|
Poppler::Document *result = Poppler::Document::load(path);
|
||||||
if(result == nullptr)
|
if(result == nullptr)
|
||||||
{
|
{
|
||||||
@ -68,8 +55,6 @@ struct Renderer
|
|||||||
PdfPreview operator()(const PdfPreview &preview)
|
PdfPreview operator()(const PdfPreview &preview)
|
||||||
{
|
{
|
||||||
PdfPreview result = preview;
|
PdfPreview result = preview;
|
||||||
if(currentTotalPreviewImageMemUsage.load() < maxTotalPreviewImageMemUsage)
|
|
||||||
{
|
|
||||||
Poppler::Document *doc = document(preview.documentPath);
|
Poppler::Document *doc = document(preview.documentPath);
|
||||||
if(doc == nullptr)
|
if(doc == nullptr)
|
||||||
{
|
{
|
||||||
@ -97,8 +82,6 @@ struct Renderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.previewImage = img;
|
result.previewImage = img;
|
||||||
currentTotalPreviewImageMemUsage += img.sizeInBytes();
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -126,7 +109,6 @@ QFuture<PdfPreview> PdfWorker::generatePreviews(const QVector<SearchResult> path
|
|||||||
double scaleY = QGuiApplication::primaryScreen()->physicalDotsPerInchY() * scalefactor;
|
double scaleY = QGuiApplication::primaryScreen()->physicalDotsPerInchY() * scalefactor;
|
||||||
|
|
||||||
QSettings setting;
|
QSettings setting;
|
||||||
qsizetype maxPreviewImageMemUsage = setting.value("maxpreviewimagesmemory", 1024 * 1024 * 1024).toLongLong();
|
return QtConcurrent::mapped(previews, Renderer(scaleX, scaleY, wordsToHighlight));
|
||||||
return QtConcurrent::mapped(previews, Renderer(scaleX, scaleY, maxPreviewImageMemUsage, wordsToHighlight));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user