void ED_preview_icon_job(const bContext *C, void *owner, ID *id, unsigned int *rect, int sizex, int sizey) { wmJob *wm_job; IconPreview *ip, *old_ip; /* suspended start means it starts after 1 timer step, see WM_jobs_timer below */ wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), owner, "Icon Preview", WM_JOB_EXCL_RENDER | WM_JOB_SUSPEND, WM_JOB_TYPE_RENDER_PREVIEW); ip = MEM_callocN(sizeof(IconPreview), "icon preview"); /* render all resolutions from suspended job too */ old_ip = WM_jobs_customdata_get(wm_job); if (old_ip) BLI_movelisttolist(&ip->sizes, &old_ip->sizes); /* customdata for preview thread */ ip->scene = CTX_data_scene(C); ip->owner = id; ip->id = id; icon_preview_add_size(ip, rect, sizex, sizey); /* setup job */ WM_jobs_customdata_set(wm_job, ip, icon_preview_free); WM_jobs_timer(wm_job, 0.1, NC_MATERIAL, NC_MATERIAL); WM_jobs_callbacks(wm_job, icon_preview_startjob_all_sizes, NULL, NULL, icon_preview_endjob); WM_jobs_start(CTX_wm_manager(C), wm_job); }
void *WM_jobs_customdata_from_type(wmWindowManager *wm, int job_type) { wmJob *wm_job = wm_job_find(wm, NULL, job_type); if (wm_job) return WM_jobs_customdata_get(wm_job); return NULL; }
void *WM_jobs_customdata(wmWindowManager *wm, void *owner) { wmJob *wm_job = wm_job_find(wm, owner, WM_JOB_TYPE_ANY); if (wm_job) return WM_jobs_customdata_get(wm_job); return NULL; }
void ED_preview_icon_job( const bContext *C, void *owner, ID *id, unsigned int *rect, int sizex, int sizey) { wmJob *wm_job; IconPreview *ip, *old_ip; ED_preview_ensure_dbase(); /* suspended start means it starts after 1 timer step, see WM_jobs_timer below */ wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), owner, "Icon Preview", WM_JOB_EXCL_RENDER | WM_JOB_SUSPEND, WM_JOB_TYPE_RENDER_PREVIEW); ip = MEM_callocN(sizeof(IconPreview), "icon preview"); /* render all resolutions from suspended job too */ old_ip = WM_jobs_customdata_get(wm_job); if (old_ip) { BLI_movelisttolist(&ip->sizes, &old_ip->sizes); } /* customdata for preview thread */ ip->bmain = CTX_data_main(C); ip->scene = CTX_data_scene(C); ip->depsgraph = CTX_data_depsgraph(C); ip->owner = owner; ip->id = id; ip->id_copy = duplicate_ids(id); icon_preview_add_size(ip, rect, sizex, sizey); /* Special threading hack: * warn main code that this preview is being rendered and cannot be freed... */ { PreviewImage *prv_img = owner; if (prv_img->tag & PRV_TAG_DEFFERED) { prv_img->tag |= PRV_TAG_DEFFERED_RENDERING; } } /* setup job */ WM_jobs_customdata_set(wm_job, ip, icon_preview_free); WM_jobs_timer(wm_job, 0.1, NC_WINDOW, NC_WINDOW); WM_jobs_callbacks(wm_job, icon_preview_startjob_all_sizes, NULL, NULL, icon_preview_endjob); WM_jobs_start(CTX_wm_manager(C), wm_job); }
void sequencer_preview_add_sound(const bContext *C, Sequence *seq) { /* first, get the preview job, if it exists */ wmJob *wm_job; PreviewJob *pj; ScrArea *sa = CTX_wm_area(C); PreviewJobAudio *audiojob = MEM_callocN(sizeof(PreviewJobAudio), "preview_audio"); wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), sa, "Strip Previews", WM_JOB_PROGRESS, WM_JOB_TYPE_SEQ_BUILD_PREVIEW); pj = WM_jobs_customdata_get(wm_job); if (!pj) { pj = MEM_callocN(sizeof(PreviewJob), "preview rebuild job"); pj->mutex = BLI_mutex_alloc(); pj->scene = CTX_data_scene(C); WM_jobs_customdata_set(wm_job, pj, free_preview_job); WM_jobs_timer(wm_job, 0.1, NC_SCENE | ND_SEQUENCER, NC_SCENE | ND_SEQUENCER); WM_jobs_callbacks(wm_job, preview_startjob, NULL, NULL, preview_endjob); } /* attempt to lock mutex of job here */ audiojob->sound = seq->sound; BLI_mutex_lock(pj->mutex); BLI_addtail(&pj->previews, audiojob); pj->total++; BLI_mutex_unlock(pj->mutex); if (!WM_jobs_is_running(wm_job)) { G.is_break = false; WM_jobs_start(CTX_wm_manager(C), wm_job); } ED_area_tag_redraw(sa); }
wmJob *EEVEE_lightbake_job_create(struct wmWindowManager *wm, struct wmWindow *win, struct Main *bmain, struct ViewLayer *view_layer, struct Scene *scene, int delay, int frame) { EEVEE_LightBake *lbake = NULL; /* only one render job at a time */ if (WM_jobs_test(wm, scene, WM_JOB_TYPE_RENDER)) { return NULL; } wmJob *wm_job = WM_jobs_get(wm, win, scene, "Bake Lighting", WM_JOB_EXCL_RENDER | WM_JOB_PRIORITY | WM_JOB_PROGRESS, WM_JOB_TYPE_LIGHT_BAKE); /* If job exists do not recreate context and depsgraph. */ EEVEE_LightBake *old_lbake = (EEVEE_LightBake *)WM_jobs_customdata_get(wm_job); if (old_lbake && (old_lbake->view_layer_input == view_layer) && (old_lbake->bmain == bmain)) { lbake = MEM_callocN(sizeof(EEVEE_LightBake), "EEVEE_LightBake"); /* Cannot reuse depsgraph for now because we cannot get the update from the * main database directly. TODO reuse depsgraph and only update positions. */ /* lbake->depsgraph = old_lbake->depsgraph; */ lbake->depsgraph = DEG_graph_new(scene, view_layer, DAG_EVAL_RENDER); lbake->mutex = BLI_mutex_alloc(); BLI_mutex_lock(old_lbake->mutex); old_lbake->own_resources = false; lbake->scene = scene; lbake->bmain = bmain; lbake->view_layer_input = view_layer; lbake->gl_context = old_lbake->gl_context; lbake->own_resources = true; lbake->delay = delay; lbake->frame = frame; if (lbake->gl_context == NULL) { lbake->gl_context = WM_opengl_context_create(); wm_window_reset_drawable(); } if (old_lbake->stop != NULL) { *old_lbake->stop = 1; } BLI_mutex_unlock(old_lbake->mutex); } else { lbake = EEVEE_lightbake_job_data_alloc(bmain, view_layer, scene, true, frame); lbake->delay = delay; } WM_jobs_customdata_set(wm_job, lbake, EEVEE_lightbake_job_data_free); WM_jobs_timer(wm_job, 0.4, NC_SCENE | NA_EDITED, 0); WM_jobs_callbacks( wm_job, EEVEE_lightbake_job, NULL, EEVEE_lightbake_update, EEVEE_lightbake_update); G.is_break = false; return wm_job; }