Blender V5.3
proxy_job.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 * SPDX-FileCopyrightText: 2003-2009 Blender Authors
3 * SPDX-FileCopyrightText: 2005-2006 Peter Schlaile <peter [at] schlaile [dot] de>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later */
6
10
11#include "MEM_guardedalloc.h"
12
13#include "DNA_scene_types.h"
14#include "DNA_sequence_types.h"
15
16#include "BLI_listbase.hh"
17
18#include "BKE_context.hh"
19
20#include "SEQ_proxy.hh"
21#include "SEQ_relations.hh"
22#include "SEQ_sequencer.hh"
23
24#include "WM_api.hh"
25#include "WM_types.hh"
26
27namespace blender::seq {
28
29static void proxy_freejob(void *pjv)
30{
31 ProxyJob *pj = static_cast<ProxyJob *>(pjv);
32 MEM_delete(pj);
33}
34
35/* Only this runs inside thread. */
36static void proxy_startjob(void *pjv, wmJobWorkerStatus *worker_status)
37{
38 ProxyJob *pj = static_cast<ProxyJob *>(pjv);
39 for (const int i : pj->queue.index_range()) {
40 ProxyBuildContext *context = pj->queue[i];
42 context, &worker_status->stop, &worker_status->do_update, [&](const float new_progress) {
43 /* Remap the progress of the current proxy to the total progress. */
44 const float total_progress = (i + new_progress) / pj->queue.size();
45 worker_status->progress = total_progress;
46 });
47
48 if (worker_status->stop) {
49 pj->stop = true;
50 fprintf(stderr, "Canceling proxy rebuild on users request...\n");
51 break;
52 }
53 }
54}
55
56static void proxy_endjob(void *pjv)
57{
58 ProxyJob *pj = static_cast<ProxyJob *>(pjv);
60
61 for (ProxyBuildContext *context : pj->queue) {
62 proxy_build_finish(context);
63 }
64 pj->queue.clear();
65
66 relations_free_imbuf(pj->scene, &ed->seqbase, false);
67
69}
70
72{
74 ProxyJob *pj = static_cast<ProxyJob *>(WM_jobs_customdata_get(wm_job));
75 if (!pj) {
76 pj = MEM_new<ProxyJob>("proxy rebuild job");
77 pj->scene = scene;
78 pj->main = CTX_data_main(C);
81 WM_jobs_callbacks(wm_job, proxy_startjob, nullptr, nullptr, proxy_endjob);
82 }
83 return pj;
84}
85
87{
91 scene,
92 "Building proxies...",
95 return wm_job;
96}
97
98} // namespace blender::seq
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define ND_SEQUENCER
Definition WM_types.hh:456
#define NC_SCENE
Definition WM_types.hh:391
void relations_free_imbuf(Scene *scene, ListBaseT< Strip > *seqbase, bool for_render)
static void proxy_endjob(void *pjv)
Definition proxy_job.cc:56
void proxy_build_finish(ProxyBuildContext *context)
Definition proxy.cc:763
void proxy_build_process(ProxyBuildContext *context, const bool *should_stop, bool *has_updated, const FunctionRef< void(float progress)> set_progress_fn)
Definition proxy.cc:743
static void proxy_freejob(void *pjv)
Definition proxy_job.cc:29
Editing * editing_get(const Scene *scene)
Definition sequencer.cc:304
ProxyJob * ED_seq_proxy_job_get(const bContext *C, wmJob *wm_job)
Definition proxy_job.cc:71
static void proxy_startjob(void *pjv, wmJobWorkerStatus *worker_status)
Definition proxy_job.cc:36
wmJob * ED_seq_proxy_wm_job_get(const bContext *C)
Definition proxy_job.cc:86
void WM_main_add_notifier(uint type, void *reference)
Scene * CTX_data_sequencer_scene(const bContext *C)
void WM_jobs_callbacks(wmJob *wm_job, wm_jobs_start_callback startjob, void(*initjob)(void *), void(*update)(void *), void(*endjob)(void *))
Definition wm_jobs.cc:407
@ WM_JOB_TYPE_SEQ_BUILD_PROXY
Definition WM_api.hh:2032
wmWindow * CTX_wm_window(const bContext *C)
void WM_jobs_customdata_set(wmJob *wm_job, void *customdata, void(*free)(void *customdata))
Definition wm_jobs.cc:377
@ WM_JOB_PROGRESS
Definition WM_api.hh:1997
void * WM_jobs_customdata_get(wmJob *wm_job)
Definition wm_jobs.cc:369
wmWindowManager * CTX_wm_manager(const bContext *C)
Main * CTX_data_main(const bContext *C)
wmJob * WM_jobs_get(wmWindowManager *wm, wmWindow *win, const void *owner, const char *name, const eWM_JobFlag flag, const eWM_JobType job_type)
Definition wm_jobs.cc:228
void WM_jobs_timer(wmJob *wm_job, double time_step, uint note, uint endnote, void(*timer_step)(void *))
Definition wm_jobs.cc:393
Vector< ProxyBuildContext * > queue
Definition SEQ_proxy.hh:63