mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-14 04:19:12 +00:00
Don't create new threads for files we couldn't generate a thumbnail for
This commit is contained in:
parent
319824021b
commit
e45e05eaff
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019-2021 Igara Studio S.A.
|
||||
// Copyright (C) 2019-2022 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -71,7 +71,7 @@ unsigned int current_file_system_version = 0;
|
||||
#endif
|
||||
|
||||
// a position in the file-system
|
||||
class FileItem : public IFileItem {
|
||||
class FileItem final : public IFileItem {
|
||||
public:
|
||||
// TODO make all these fields private
|
||||
std::string m_keyname;
|
||||
@ -123,6 +123,13 @@ public:
|
||||
m_thumbnailProgress = progress;
|
||||
}
|
||||
|
||||
bool needThumbnail() const override {
|
||||
return
|
||||
!isBrowsable() &&
|
||||
m_thumbnail == nullptr &&
|
||||
m_thumbnailProgress < 1.0;
|
||||
}
|
||||
|
||||
os::SurfaceRef getThumbnail() override;
|
||||
void setThumbnail(const os::SurfaceRef& thumbnail) override;
|
||||
|
||||
@ -593,6 +600,8 @@ os::SurfaceRef FileItem::getThumbnail()
|
||||
|
||||
void FileItem::setThumbnail(const os::SurfaceRef& newThumbnail)
|
||||
{
|
||||
m_thumbnailProgress = 1.0;
|
||||
|
||||
if (newThumbnail)
|
||||
newThumbnail->ref();
|
||||
auto old = m_thumbnail.exchange(newThumbnail.get());
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019-2020 Igara Studio S.A.
|
||||
// Copyright (C) 2019-2022 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -87,8 +87,10 @@ namespace app {
|
||||
virtual double getThumbnailProgress() = 0;
|
||||
virtual void setThumbnailProgress(double progress) = 0;
|
||||
|
||||
virtual bool needThumbnail() const = 0;
|
||||
virtual os::SurfaceRef getThumbnail() = 0;
|
||||
virtual void setThumbnail(const os::SurfaceRef& thumbnail) = 0;
|
||||
|
||||
};
|
||||
|
||||
} // namespace app
|
||||
|
@ -176,17 +176,26 @@ private:
|
||||
THUMB_TRACE("FOP done with thumbnail: %s %s\n",
|
||||
m_item.fileitem->fileName().c_str(),
|
||||
(m_fop->isStop() ? " (stop)": ""));
|
||||
|
||||
// Reset the m_item (first the fileitem so this worker is not
|
||||
// associated to this fileitem anymore, and then the FileOp).
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
m_item.fileitem = nullptr;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
m_fop->setError("Error loading file:\n%s", e.what());
|
||||
}
|
||||
|
||||
if (!m_fop->isStop()) {
|
||||
// Set a nullptr thumbnail if we failed loading the given file,
|
||||
// in this way we're not going to re-try generating this same
|
||||
// thumbnail.
|
||||
if (m_item.fileitem->needThumbnail())
|
||||
m_item.fileitem->setThumbnail(nullptr);
|
||||
}
|
||||
|
||||
// Reset the m_item (first the fileitem so this worker is not
|
||||
// associated to this fileitem anymore, and then the FileOp).
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
m_item.fileitem = nullptr;
|
||||
}
|
||||
|
||||
m_fop->done();
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
@ -262,8 +271,7 @@ bool ThumbnailGenerator::checkWorkers()
|
||||
|
||||
void ThumbnailGenerator::generateThumbnail(IFileItem* fileitem)
|
||||
{
|
||||
if (fileitem->isBrowsable() ||
|
||||
fileitem->getThumbnail())
|
||||
if (!fileitem->needThumbnail())
|
||||
return;
|
||||
|
||||
if (fileitem->getThumbnailProgress() > 0.0) {
|
||||
@ -302,11 +310,12 @@ void ThumbnailGenerator::generateThumbnail(IFileItem* fileitem)
|
||||
fileitem->fileName().c_str(),
|
||||
FILE_LOAD_SEQUENCE_NONE |
|
||||
FILE_LOAD_ONE_FRAME));
|
||||
if (!fop)
|
||||
return;
|
||||
|
||||
if (fop->hasError())
|
||||
if (!fop || fop->hasError()) {
|
||||
// Set a nullptr thumbnail so we don't try to generate a thumbnail
|
||||
// for this fileitem again.
|
||||
fileitem->setThumbnail(nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
m_remainingItems.push(Item(fileitem, fop.get()));
|
||||
fop.release();
|
||||
|
@ -885,7 +885,7 @@ void FileList::selectIndex(int index)
|
||||
|
||||
void FileList::generateThumbnailForFileItem(IFileItem* fi)
|
||||
{
|
||||
if (fi && animation() == ANI_NONE) {
|
||||
if (fi && fi->needThumbnail() && animation() == ANI_NONE) {
|
||||
auto it = std::find(m_generateThumbnailsForTheseItems.begin(),
|
||||
m_generateThumbnailsForTheseItems.end(), fi);
|
||||
if (it != m_generateThumbnailsForTheseItems.end())
|
||||
|
Loading…
x
Reference in New Issue
Block a user