From bb80d168af2c5e36903dd61473fdbd3840846d7f Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 27 Oct 2021 15:20:30 +0200 Subject: Stop download of thumbnail if the thumbnail is no longer visible on the screen --- include/AsyncImageLoader.hpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/AsyncImageLoader.hpp b/include/AsyncImageLoader.hpp index 77fd5b4..94b225d 100644 --- a/include/AsyncImageLoader.hpp +++ b/include/AsyncImageLoader.hpp @@ -54,6 +54,15 @@ namespace QuickMedia { // Note: this method is not thread-safe void update(); private: + struct Download { + ReadProgram read_program; + int64_t download_start = 0; + Path thumbnail_path; + std::shared_ptr thumbnail_data; + sf::Vector2i resize_target_size; + std::string url; + }; + AsyncImageLoader(); ~AsyncImageLoader(); AsyncImageLoader(AsyncImageLoader &other) = delete; @@ -65,16 +74,9 @@ namespace QuickMedia { // Returns -1 if all threads are busy int get_free_load_index() const; - private: - struct Download { - ReadProgram read_program; - int64_t download_start = 0; - Path thumbnail_path; - std::shared_ptr thumbnail_data; - sf::Vector2i resize_target_size; - std::string url; - }; + void reset_download(Download &download); + private: std::mutex download_mutex; // TODO: Use curl single-threaded multi-download feature instead Download downloads[NUM_IMAGE_LOAD_PARALLEL]; -- cgit v1.2.3