Fix: Preview images didn't load progressively as intended

Custom preview images loaded from disk are supposed to load one by one
in a background thread, but pop up in the UI as they get ready. This
gradual/progressive loading wasn't working correctly, previews would
only show up after all current preview requests were handled. I think
there would still be some progressive loading, since handling a batch of
requests might finish before all requests for the current frame are in.
Now it works as intended, by actually tagging loaded previews.

Mistake in 16ab6111f7.

Noticed while working on #131871.
This commit is contained in:
Julian Eisel
2025-01-24 20:44:33 +01:00
parent 315e7e04a8
commit 5055adc1c0

View File

@@ -9,6 +9,7 @@
/* global includes */
#include <algorithm>
#include <atomic>
#include <cmath>
#include <cstdlib>
#include <cstring>
@@ -1726,6 +1727,12 @@ class PreviewLoadJob {
PreviewImage *preview;
/** Requested size. */
eIconSizes icon_size;
std::atomic<int> done = false;
RequestedPreview(PreviewImage *preview, eIconSizes icon_size)
: preview(preview), icon_size(icon_size)
{
}
};
/** The previews that are still to be loaded. */
@@ -1793,15 +1800,12 @@ void PreviewLoadJob::load_jobless(PreviewImage *preview, const eIconSizes icon_s
void PreviewLoadJob::push_load_request(PreviewImage *preview, const eIconSizes icon_size)
{
BLI_assert(preview->runtime->deferred_loading_data);
RequestedPreview requested_preview{};
requested_preview.preview = preview;
requested_preview.icon_size = icon_size;
preview->flag[icon_size] |= PRV_RENDERING;
/* Warn main thread code that this preview is being rendered and cannot be freed. */
preview->runtime->tag |= PRV_TAG_DEFFERED_RENDERING;
requested_previews_.push_back(requested_preview);
requested_previews_.emplace_back(preview, icon_size);
BLI_thread_queue_push(todo_queue_, &requested_previews_.back());
}
@@ -1852,6 +1856,7 @@ void PreviewLoadJob::run_fn(void *customdata, wmJobWorkerStatus *worker_status)
IMB_freeImBuf(thumb);
}
request->done = true;
worker_status->do_update = true;
}
@@ -1883,7 +1888,7 @@ void PreviewLoadJob::update_fn(void *customdata)
{
RequestedPreview &requested = *request_it;
/* Skip items that are not done loading yet. */
if (requested.preview->runtime->tag & PRV_TAG_DEFFERED_RENDERING) {
if (!requested.done) {
++request_it;
continue;
}