Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_file/filelist.c
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| FLC_IS_INIT = 1 << 0, | FLC_IS_INIT = 1 << 0, | ||||
| FLC_PREVIEWS_ACTIVE = 1 << 1, | FLC_PREVIEWS_ACTIVE = 1 << 1, | ||||
| }; | }; | ||||
| typedef struct FileListEntryPreview { | typedef struct FileListEntryPreview { | ||||
| char path[FILE_MAX]; | char path[FILE_MAX]; | ||||
| uint flags; | uint flags; | ||||
| int index; | int index; | ||||
| int attributes; /* from FileDirEntry. */ | |||||
| int icon_id; | int icon_id; | ||||
| } FileListEntryPreview; | } FileListEntryPreview; | ||||
| /* Dummy wrapper around FileListEntryPreview to ensure we do not access freed memory when freeing | /* Dummy wrapper around FileListEntryPreview to ensure we do not access freed memory when freeing | ||||
| * tasks' data (see T74609). */ | * tasks' data (see T74609). */ | ||||
| typedef struct FileListEntryPreviewTaskData { | typedef struct FileListEntryPreviewTaskData { | ||||
| FileListEntryPreview *preview; | FileListEntryPreview *preview; | ||||
| } FileListEntryPreviewTaskData; | } FileListEntryPreviewTaskData; | ||||
| ▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | |||||
| source = THB_SOURCE_MOVIE; | source = THB_SOURCE_MOVIE; | ||||
| } | } | ||||
| else if (preview->flags & FILE_TYPE_FTFONT) { | else if (preview->flags & FILE_TYPE_FTFONT) { | ||||
| source = THB_SOURCE_FONT; | source = THB_SOURCE_FONT; | ||||
| } | } | ||||
| IMB_thumb_path_lock(preview->path); | IMB_thumb_path_lock(preview->path); | ||||
| /* Always generate biggest preview size for now, it's simpler and avoids having to re-generate | /* 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. */ | * in case user switch to a bigger preview size. Do not create preview when file is offline. */ | ||||
| ImBuf *imbuf = IMB_thumb_manage(preview->path, THB_LARGE, source); | ImBuf *imbuf = (preview->attributes & FILE_ATTR_OFFLINE) ? | ||||
| IMB_thumb_read(preview->path, THB_LARGE) : | |||||
| IMB_thumb_manage(preview->path, THB_LARGE, source); | |||||
| IMB_thumb_path_unlock(preview->path); | IMB_thumb_path_unlock(preview->path); | ||||
| if (imbuf) { | if (imbuf) { | ||||
| preview->icon_id = BKE_icon_imbuf_create(imbuf); | preview->icon_id = BKE_icon_imbuf_create(imbuf); | ||||
| } | } | ||||
| /* Move ownership to the done queue. */ | /* Move ownership to the done queue. */ | ||||
| preview_taskdata->preview = NULL; | preview_taskdata->preview = NULL; | ||||
| ▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static void filelist_cache_previews_push(FileList *filelist, FileDirEntry *entry, const int index) | static void filelist_cache_previews_push(FileList *filelist, FileDirEntry *entry, const int index) | ||||
| { | { | ||||
| FileListEntryCache *cache = &filelist->filelist_cache; | FileListEntryCache *cache = &filelist->filelist_cache; | ||||
| BLI_assert(cache->flags & FLC_PREVIEWS_ACTIVE); | BLI_assert(cache->flags & FLC_PREVIEWS_ACTIVE); | ||||
| if (!entry->preview_icon_id && (entry->attributes & FILE_ATTR_OFFLINE)) { | |||||
| entry->flags |= FILE_ENTRY_INVALID_PREVIEW; | |||||
| return; | |||||
| } | |||||
| if (entry->preview_icon_id) { | if (entry->preview_icon_id) { | ||||
| return; | return; | ||||
| } | } | ||||
| if (entry->flags & (FILE_ENTRY_INVALID_PREVIEW | FILE_ENTRY_PREVIEW_LOADING)) { | if (entry->flags & (FILE_ENTRY_INVALID_PREVIEW | FILE_ENTRY_PREVIEW_LOADING)) { | ||||
| return; | return; | ||||
| } | } | ||||
| Show All 10 Lines | |||||
| } | } | ||||
| filelist_cache_preview_ensure_running(cache); | filelist_cache_preview_ensure_running(cache); | ||||
| entry->flags |= FILE_ENTRY_PREVIEW_LOADING; | entry->flags |= FILE_ENTRY_PREVIEW_LOADING; | ||||
| FileListEntryPreview *preview = MEM_mallocN(sizeof(*preview), __func__); | FileListEntryPreview *preview = MEM_mallocN(sizeof(*preview), __func__); | ||||
| preview->index = index; | preview->index = index; | ||||
| preview->flags = entry->typeflag; | preview->flags = entry->typeflag; | ||||
| preview->attributes = entry->attributes; | |||||
| preview->icon_id = 0; | preview->icon_id = 0; | ||||
| if (preview_in_memory) { | if (preview_in_memory) { | ||||
| /* TODO(mano-wii): No need to use the thread API here. */ | /* TODO(mano-wii): No need to use the thread API here. */ | ||||
| BLI_assert(BKE_previewimg_is_finished(preview_in_memory, ICON_SIZE_PREVIEW)); | BLI_assert(BKE_previewimg_is_finished(preview_in_memory, ICON_SIZE_PREVIEW)); | ||||
| preview->path[0] = '\0'; | preview->path[0] = '\0'; | ||||
| ImBuf *imbuf = BKE_previewimg_to_imbuf(preview_in_memory, ICON_SIZE_PREVIEW); | ImBuf *imbuf = BKE_previewimg_to_imbuf(preview_in_memory, ICON_SIZE_PREVIEW); | ||||
| if (imbuf) { | if (imbuf) { | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||