Thumbnails: Always use cached thumbnails for offline files
bd9f94e917 made it so the file browser doesn't bring files online for
the purpuse of creating their thumbnail, because that can take a while.
Instead it uses a previously cached thumbnail if available. This should
be the behavior for all cases thumbnails are requested, it's not only
the file browser that does this.
In fact it makes sense to move this into the normal function to "manage"
thumbnails (that is, load and if necessary (re)create cached
thumbnails) since there are no currently known use-cases for
different behavior.
Also, seems like the previous solution didn't work when loading ID
previews from offline .blend files. For that we need to use the path to
the .blend file to check the offline status, not the full path to the ID.
Found while working on #109234 (Use UI preview system for async loading of
file/asset previews).
Pull Request: https://projects.blender.org/blender/blender/pulls/112101
This commit is contained in:
committed by
Julian Eisel
parent
98e33adac2
commit
3589533908
@@ -183,7 +183,6 @@ struct FileListEntryPreview {
|
||||
char filepath[FILE_MAX_LIBEXTRA];
|
||||
uint flags;
|
||||
int index;
|
||||
int attributes; /* from FileDirEntry. */
|
||||
int icon_id;
|
||||
};
|
||||
|
||||
@@ -1534,10 +1533,8 @@ static void filelist_cache_preview_runf(TaskPool *__restrict pool, void *taskdat
|
||||
|
||||
IMB_thumb_path_lock(preview->filepath);
|
||||
/* Always generate biggest preview size for now, it's simpler and avoids having to re-generate
|
||||
* in case user switch to a bigger preview size. Do not create preview when file is offline. */
|
||||
ImBuf *imbuf = (preview->attributes & FILE_ATTR_OFFLINE) ?
|
||||
IMB_thumb_read(preview->filepath, THB_LARGE) :
|
||||
IMB_thumb_manage(preview->filepath, THB_LARGE, source);
|
||||
* in case user switch to a bigger preview size. */
|
||||
ImBuf *imbuf = IMB_thumb_manage(preview->filepath, THB_LARGE, source);
|
||||
IMB_thumb_path_unlock(preview->filepath);
|
||||
if (imbuf) {
|
||||
preview->icon_id = BKE_icon_imbuf_create(imbuf);
|
||||
@@ -1667,7 +1664,6 @@ static void filelist_cache_previews_push(FileList *filelist, FileDirEntry *entry
|
||||
FileListEntryPreview *preview = MEM_new<FileListEntryPreview>(__func__);
|
||||
preview->index = index;
|
||||
preview->flags = entry->typeflag;
|
||||
preview->attributes = entry->attributes;
|
||||
preview->icon_id = 0;
|
||||
|
||||
if (preview_in_memory) {
|
||||
|
||||
@@ -74,6 +74,9 @@ void IMB_thumb_delete(const char *file_or_lib_path, ThumbSize size);
|
||||
|
||||
/**
|
||||
* Create the thumb if necessary and manage failed and old thumbs.
|
||||
* Will not attempt to (re)create thumbnails of offline files. In this case only a preexisting
|
||||
* thumbnail is returned, or null if none was found.
|
||||
*
|
||||
* \param file_or_lib_path: File path or library-ID path (e.g. `/a/b.blend/Material/MyMaterial`) to
|
||||
* the thumbnail to be created/managed.
|
||||
*/
|
||||
|
||||
@@ -557,6 +557,17 @@ ImBuf *IMB_thumb_manage(const char *file_or_lib_path, ThumbSize size, ThumbSourc
|
||||
if (!uri_from_filename(file_or_lib_path, uri)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* Don't access offline files, only use already existing thumbnails (don't recreate). */
|
||||
const eFileAttributes file_attributes = BLI_file_attributes(file_path);
|
||||
if (file_attributes & FILE_ATTR_OFFLINE) {
|
||||
char thumb_path[FILE_MAX];
|
||||
if (thumbpath_from_uri(uri, thumb_path, sizeof(thumb_path), size)) {
|
||||
return IMB_loadiffname(thumb_path, IB_rect | IB_metadata, nullptr);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
char thumb_path[FILE_MAX];
|
||||
if (thumbpath_from_uri(uri, thumb_path, sizeof(thumb_path), THB_FAIL)) {
|
||||
/* failure thumb exists, don't try recreating */
|
||||
|
||||
Reference in New Issue
Block a user