From 633ccf9c8d1f32b2f3a312f0e95e4ed6fbd33dd8 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 19 Nov 2021 03:05:52 +0100 Subject: Revert back to loading thumbnails with multiple threads instead of loading thumbnails after requested in render loop --- src/AsyncImageLoader.cpp | 34 ++++------------------------------ 1 file changed, 4 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/AsyncImageLoader.cpp b/src/AsyncImageLoader.cpp index c1d4aab..b9bcd30 100644 --- a/src/AsyncImageLoader.cpp +++ b/src/AsyncImageLoader.cpp @@ -253,23 +253,11 @@ namespace QuickMedia { load_thread = AsyncTask([this]() mutable { std::optional thumbnail_load_data_opt; while(image_thumbnail_create_queue.is_running()) { - ThumbnailLoadData load_image_data; - { - std::lock_guard lock(image_load_mutex); - if(current_loading_image.thumbnail_data) { - load_image_data = std::move(current_loading_image); - current_loading_image = ThumbnailLoadData(); - } - } - - if(load_image_data.thumbnail_data) { - load_processed_thumbnail(load_image_data); - load_image_data = ThumbnailLoadData(); - } - thumbnail_load_data_opt = image_thumbnail_create_queue.pop_if_available(); if(thumbnail_load_data_opt) { process_thumbnail(thumbnail_load_data_opt.value()); + if(thumbnail_load_data_opt.value().thumbnail_data->loading_state == LoadingState::READY_TO_LOAD) + load_processed_thumbnail(thumbnail_load_data_opt.value()); thumbnail_load_data_opt = std::nullopt; } @@ -285,7 +273,7 @@ namespace QuickMedia { if(status == 0 && rename_atomic(tmp_thumbnail_path.data.c_str(), download.thumbnail_path.data.c_str()) == 0) { fprintf(stderr, "Download duration for %s: %ld ms\n", download.url.c_str(), get_boottime_milliseconds() - download.download_start); ThumbnailLoadData load_data = { std::move(download.url), std::move(download.thumbnail_path), false, download.thumbnail_data, download.resize_target_size }; - process_thumbnail(load_data); + image_thumbnail_create_queue.push(std::move(load_data)); } else { fprintf(stderr, "Thumbnail download failed for %s\n", download.url.c_str()); } @@ -379,15 +367,7 @@ namespace QuickMedia { thumbnail_data->thumbnail_path = get_cache_dir().join("thumbnails").join(sha256.getHash()); } - if(!load_thumbnail(url, local, resize_target_size, thumbnail_data, thumbnail_data->thumbnail_path)) - return thumbnail_data; - - if(thumbnail_data->loading_state == LoadingState::READY_TO_LOAD) { - std::lock_guard lock(image_load_mutex); - if(!current_loading_image.thumbnail_data) - current_loading_image = { url, thumbnail_data->thumbnail_path, local, thumbnail_data, resize_target_size }; - } - + load_thumbnail(url, local, resize_target_size, thumbnail_data, thumbnail_data->thumbnail_path); return thumbnail_data; } @@ -412,12 +392,6 @@ namespace QuickMedia { return load_data.path.data == it->first; }); - { - std::lock_guard lock(image_load_mutex); - if(current_loading_image.thumbnail_data == it->second) - current_loading_image = ThumbnailLoadData(); - } - it = thumbnails.erase(it); loaded_textures_changed = true; } else { -- cgit v1.2.3