Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_file/filelist.c
| Show First 20 Lines • Show All 1,258 Lines • ▼ Show 20 Lines | for (entry = filelist_intern->entries.first; entry; entry = entry_next) { | ||||
| entry_next = entry->next; | entry_next = entry->next; | ||||
| filelist_intern_entry_free(entry); | filelist_intern_entry_free(entry); | ||||
| } | } | ||||
| BLI_listbase_clear(&filelist_intern->entries); | BLI_listbase_clear(&filelist_intern->entries); | ||||
| MEM_SAFE_FREE(filelist_intern->filtered); | MEM_SAFE_FREE(filelist_intern->filtered); | ||||
| } | } | ||||
| static void filelist_cache_preview_runf(TaskPool *__restrict pool, | static void filelist_cache_preview_runf(TaskPool *__restrict pool, void *taskdata) | ||||
| void *taskdata, | |||||
| int UNUSED(threadid)) | |||||
| { | { | ||||
| FileListEntryCache *cache = BLI_task_pool_userdata(pool); | FileListEntryCache *cache = BLI_task_pool_tbb_user_data(pool); | ||||
| FileListEntryPreviewTaskData *preview_taskdata = taskdata; | FileListEntryPreviewTaskData *preview_taskdata = taskdata; | ||||
| FileListEntryPreview *preview = preview_taskdata->preview; | FileListEntryPreview *preview = preview_taskdata->preview; | ||||
| ThumbSource source = 0; | ThumbSource source = 0; | ||||
| // printf("%s: Start (%d)...\n", __func__, threadid); | // printf("%s: Start (%d)...\n", __func__, threadid); | ||||
| // printf("%s: %d - %s - %p\n", __func__, preview->index, preview->path, preview->img); | // printf("%s: %d - %s - %p\n", __func__, preview->index, preview->path, preview->img); | ||||
| Show All 21 Lines | static void filelist_cache_preview_runf(TaskPool *__restrict pool, void *taskdata) | ||||
| /* That way task freeing function won't free th preview, since it does not own it anymore. */ | /* That way task freeing function won't free th preview, since it does not own it anymore. */ | ||||
| atomic_cas_ptr((void **)&preview_taskdata->preview, preview, NULL); | atomic_cas_ptr((void **)&preview_taskdata->preview, preview, NULL); | ||||
| BLI_thread_queue_push(cache->previews_done, preview); | BLI_thread_queue_push(cache->previews_done, preview); | ||||
| // printf("%s: End (%d)...\n", __func__, threadid); | // printf("%s: End (%d)...\n", __func__, threadid); | ||||
| } | } | ||||
| static void filelist_cache_preview_freef(TaskPool *__restrict UNUSED(pool), | static void filelist_cache_preview_freef(TaskPool *__restrict UNUSED(pool), void *taskdata) | ||||
| void *taskdata, | |||||
| int UNUSED(threadid)) | |||||
| { | { | ||||
| FileListEntryPreviewTaskData *preview_taskdata = taskdata; | FileListEntryPreviewTaskData *preview_taskdata = taskdata; | ||||
| FileListEntryPreview *preview = preview_taskdata->preview; | FileListEntryPreview *preview = preview_taskdata->preview; | ||||
| /* preview_taskdata->preview is atomically set to NULL once preview has been processed and sent | /* preview_taskdata->preview is atomically set to NULL once preview has been processed and sent | ||||
| * to previews_done queue. */ | * to previews_done queue. */ | ||||
| if (preview != NULL) { | if (preview != NULL) { | ||||
| if (preview->img) { | if (preview->img) { | ||||
| IMB_freeImBuf(preview->img); | IMB_freeImBuf(preview->img); | ||||
| } | } | ||||
| MEM_freeN(preview); | MEM_freeN(preview); | ||||
| } | } | ||||
| MEM_freeN(preview_taskdata); | MEM_freeN(preview_taskdata); | ||||
| } | } | ||||
| static void filelist_cache_preview_ensure_running(FileListEntryCache *cache) | static void filelist_cache_preview_ensure_running(FileListEntryCache *cache) | ||||
| { | { | ||||
| if (!cache->previews_pool) { | if (!cache->previews_pool) { | ||||
| TaskScheduler *scheduler = BLI_task_scheduler_get(); | TaskScheduler *scheduler = BLI_task_scheduler_legacy_get(); | ||||
| cache->previews_pool = BLI_task_pool_create_background(scheduler, cache, TASK_PRIORITY_LOW); | cache->previews_pool = BLI_task_pool_tbb_create_background( | ||||
| scheduler, cache, TASK_PRIORITY_LOW); | |||||
| cache->previews_done = BLI_thread_queue_init(); | cache->previews_done = BLI_thread_queue_init(); | ||||
| IMB_thumb_locks_acquire(); | IMB_thumb_locks_acquire(); | ||||
| } | } | ||||
| } | } | ||||
| static void filelist_cache_previews_clear(FileListEntryCache *cache) | static void filelist_cache_previews_clear(FileListEntryCache *cache) | ||||
| { | { | ||||
| if (cache->previews_pool) { | if (cache->previews_pool) { | ||||
| BLI_task_pool_cancel(cache->previews_pool); | BLI_task_pool_tbb_cancel(cache->previews_pool); | ||||
| FileListEntryPreview *preview; | FileListEntryPreview *preview; | ||||
| while ((preview = BLI_thread_queue_pop_timeout(cache->previews_done, 0))) { | while ((preview = BLI_thread_queue_pop_timeout(cache->previews_done, 0))) { | ||||
| // printf("%s: DONE %d - %s - %p\n", __func__, preview->index, preview->path, | // printf("%s: DONE %d - %s - %p\n", __func__, preview->index, preview->path, | ||||
| // preview->img); | // preview->img); | ||||
| if (preview->img) { | if (preview->img) { | ||||
| IMB_freeImBuf(preview->img); | IMB_freeImBuf(preview->img); | ||||
| } | } | ||||
| MEM_freeN(preview); | MEM_freeN(preview); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void filelist_cache_previews_free(FileListEntryCache *cache) | static void filelist_cache_previews_free(FileListEntryCache *cache) | ||||
| { | { | ||||
| if (cache->previews_pool) { | if (cache->previews_pool) { | ||||
| BLI_thread_queue_nowait(cache->previews_done); | BLI_thread_queue_nowait(cache->previews_done); | ||||
| filelist_cache_previews_clear(cache); | filelist_cache_previews_clear(cache); | ||||
| BLI_thread_queue_free(cache->previews_done); | BLI_thread_queue_free(cache->previews_done); | ||||
| BLI_task_pool_free(cache->previews_pool); | BLI_task_pool_tbb_free(cache->previews_pool); | ||||
| cache->previews_pool = NULL; | cache->previews_pool = NULL; | ||||
| cache->previews_done = NULL; | cache->previews_done = NULL; | ||||
| IMB_thumb_locks_release(); | IMB_thumb_locks_release(); | ||||
| } | } | ||||
| cache->flags &= ~FLC_PREVIEWS_ACTIVE; | cache->flags &= ~FLC_PREVIEWS_ACTIVE; | ||||
| } | } | ||||
| Show All 15 Lines | if (!entry->image && !(entry->flags & FILE_ENTRY_INVALID_PREVIEW) && | ||||
| preview->img = NULL; | preview->img = NULL; | ||||
| // printf("%s: %d - %s - %p\n", __func__, preview->index, preview->path, preview->img); | // printf("%s: %d - %s - %p\n", __func__, preview->index, preview->path, preview->img); | ||||
| filelist_cache_preview_ensure_running(cache); | filelist_cache_preview_ensure_running(cache); | ||||
| FileListEntryPreviewTaskData *preview_taskdata = MEM_mallocN(sizeof(*preview_taskdata), | FileListEntryPreviewTaskData *preview_taskdata = MEM_mallocN(sizeof(*preview_taskdata), | ||||
| __func__); | __func__); | ||||
| preview_taskdata->preview = preview; | preview_taskdata->preview = preview; | ||||
| BLI_task_pool_push(cache->previews_pool, | BLI_task_pool_tbb_push(cache->previews_pool, | ||||
| filelist_cache_preview_runf, | filelist_cache_preview_runf, | ||||
| preview_taskdata, | preview_taskdata, | ||||
| true, | true, | ||||
| filelist_cache_preview_freef); | filelist_cache_preview_freef); | ||||
| } | } | ||||
| } | } | ||||
| static void filelist_cache_init(FileListEntryCache *cache, size_t cache_size) | static void filelist_cache_init(FileListEntryCache *cache, size_t cache_size) | ||||
| { | { | ||||
| BLI_listbase_clear(&cache->cached_entries); | BLI_listbase_clear(&cache->cached_entries); | ||||
| cache->block_cursor = cache->block_start_index = cache->block_center_index = | cache->block_cursor = cache->block_start_index = cache->block_center_index = | ||||
| ▲ Show 20 Lines • Show All 1,689 Lines • Show Last 20 Lines | |||||